/* * How to use Scanner to read from keyboard */ import java.util.*; class Scanner_fromKeyboard{ public static void main(String args[]) { try{ Scanner sc = new Scanner(System.in); String s = ""; System.out.println("What is your name?\n"); s = sc.next(); System.out.println("My name is " + s + "\n"); int age; System.out.println("How old are you?\n"); age = sc.nextInt(); System.out.println("You are " + age + "years old."); sc.close(); }catch(InputMismatchException ime){ System.out.println("Input Error..."); }catch(Exception e) { e.printStackTrace(); }//catch }//main }//Scanner_fromKeyboard