Scanner Class

/** * I/O > Console I/O > ConsoleIOScanner.java * * Reads text from standard input using console I/O using the Scanner class. * This does not work in versions of Java previous to Java 5 (aka 1.5) * @author Dale Reed */ import java.util.Scanner; public class ConsoleScannerInput { public static void main(String[] args) { Scanner keyboard = new Scanner( System.in); System.out.print( "Enter your first name: " ); String first = keyboard.next(); // read a string System.out.print( "Enter your last name and your age: " ); String last = keyboard.next(); // read a string int age = keyboard.nextInt(); // read an integer 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 and your age: Reed 41 Hello Dale Reed In one year you will be 42 years old */