-
Skipping Scanner
I have this problem with using the Scanner...inside the main method:
Scanner scan=new Scanner(System.in);
String name;
int age,id;
System.out.println("Enter ID: ?\b");
id=scan.nextInt();
System.out.println("Enter Name: ?\b");
name=scan.nextLine();
System.out.println("Enter Age: ?\b");
age=scan.nextInt();
If i input for the id, the Enter name and Enter Age would print out, making me input the age and skipping the name...
pls help me get rid of skipping...tnx!
-
Instead of scan.nextInt() use
Code:
Integer.parseInt(scan.nextLine());
-
it actually worked!!! thanks much!!