Code example for Scanner

Methods: closenextnextInt

0
 
	/** 
	 * @param args 
	 */ 
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		System.out.print("Please enter your name: ");
		String name1 = input.next();
//		String name1 = input.nextLine(); 
		System.out.print("Please enter your age: ");
		int age1 = input.nextInt();
		 
		System.out.print("Please enter your name: ");
		String name2 = input.next();
//		String name2 = input.nextLine(); 
		System.out.print("Please enter your age: ");
		int age2 = input.nextInt();
		 
		System.out.println(name1 + " is " + age1);
		System.out.println(name2 + " is " + age2);
		 
		input.close();
	} 
 
}