/**
* I/O > Console I/O > ConsoleInput.java
*
* Reads text from standard input using console I/O. To use the System.in
* object, you must wrap it in a InputStreamReader object and then wrap it in
* a BufferedReader object. In addition, you must somehow handle the
* IOException that the .readLine() method throws. You can do this either by
* putting "throws IOException" after the method header or else enclose it
* in a try block. For this example, we add "throws IOException" to the end
* of the main() method header, which is generally the easiest way to go.
* @author Dale Reed, Feihong Hsu
*/
import java.io.*;
public class ConsoleInput {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(
new InputStreamReader(System.in) );
System.out.print( "Enter your first name: " );
String first = reader.readLine();
// It is more difficult to combine the two inputs below on the same input line
System.out.print( "Enter your last name: " );
String last = reader.readLine();
System.out.print( "Enter your age: " );
int age = Integer.parseInt( reader.readLine() );
System.out.println( "Hello " + first + " " + last);
System.out.printf( "In one year you will be %d years old", age + 1);
}
}
/* Output: Assuming your input is "Dale", "Reed", "41"
Enter your first name: Dale
Enter your last name: Reed
Enter your age: 41
Hello Dale Reed
In one year you will be 42 years old
*/