Results 1 to 3 of 3
  1. #1
    chari_autumn is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Question 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!

  2. #2
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    5

    Default

    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.

  3. #3
    chari_autumn is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default

    it actually worked!!! thanks much!!
    Last edited by chari_autumn; 01-04-2011 at 07:34 AM. Reason: forgot to add sumthing...

Similar Threads

  1. Skipping lines during debugging
    By Taxi in forum New To Java
    Replies: 5
    Last Post: 04-01-2014, 05:03 PM
  2. Using scanner for CSV
    By getName() in forum Advanced Java
    Replies: 7
    Last Post: 06-20-2010, 05:33 PM
  3. Skipping links!!!
    By jvh in forum New To Java
    Replies: 2
    Last Post: 03-04-2010, 01:11 AM
  4. need help with scanner
    By whiterex in forum New To Java
    Replies: 1
    Last Post: 04-22-2008, 02:41 PM
  5. skipping input
    By windie_86 in forum New To Java
    Replies: 1
    Last Post: 02-12-2008, 08:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •