Results 1 to 3 of 3
Thread: Skipping Scanner
- 01-04-2011, 04:48 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 2
- Rep Power
- 0
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!
- 01-04-2011, 05:38 AM #2
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
Instead of scan.nextInt() use
Java Code:Integer.parseInt(scan.nextLine());
Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 01-04-2011, 06:29 AM #3
Member
- Join Date
- Jan 2011
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Using scanner for CSV
By getName() in forum Advanced JavaReplies: 7Last Post: 06-20-2010, 04:33 PM -
Skipping links!!!
By jvh in forum New To JavaReplies: 2Last Post: 03-04-2010, 12:11 AM -
Skipping lines during debugging
By Taxi in forum New To JavaReplies: 2Last Post: 12-27-2008, 03:53 AM -
need help with scanner
By whiterex in forum New To JavaReplies: 1Last Post: 04-22-2008, 01:41 PM -
skipping input
By windie_86 in forum New To JavaReplies: 1Last Post: 02-12-2008, 07:09 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks