Java-Can't take two inputs using Scanner
Could someone please check whats wrong with the following code? It throws an exception as follows when i try to run it import java.util.Scanner; class myClass{ public static void main(String[]args){ String name; int age; Scanner in=new Scanner(System.in); System.out.println("What is your name? "); name = in.nextLine(); System.out.println("What is your age? "); age = in.nextInt(); System.out.printf("Hello %s, age %d\n", name, age); } } (What is your name? What is your age? Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at name.main(name.java:23))