import java.util.Scanner; /** * This version of the ScannerTest shows the use of two different * Scanner instances, one to read string input and one to read * numeric and character input. * @author Heidi J. C. Ellis * date: 9/17/08 */ public class ScannerTest1 { public static void main(String[] args) { Scanner stringInput, numberInput; String name, address; int age, grade; // Create two scanner instances, one to read all // the strings the other to read all the numbers. // This gets us around having to // "eat" the carriage return when using a single // scanner instance and switching between numeric // and string input. stringInput = new Scanner(System.in); //String numberInput = new Scanner(System.in); // Numbers System.out.print("Enter name: "); name = stringInput.nextLine(); System.out.print("Enter age: " ); age = numberInput.nextInt(); System.out.print("Enter address: " ); address = stringInput.nextLine(); System.out.print("Enter grade: " ); grade = numberInput.nextInt(); // Print the contents of the variables System.out.println("Name: " + name); System.out.println("Age: " + age); System.out.println("Address: " + address); System.out.println("Grade: " + grade); } }