previous |
start |
next .... [Slide 39] ....
Reading Input
- Read console input from System.in
- System.in is an InputStream: reads
bytes
- We want a Reader
that reads characters
- Turn System.in
into InputStreamReader
- Also want to read entire lines
- Use BufferedReader:
BufferedReader console = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("How old are you?");
String input = console.readLine();
int age = Integer.parseInt(input);
-
previous |
start |
next .... [Slide 39] ....