Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23
  1. #21
    buildakicker is offline nOOb :)
    Join Date
    Jul 2011
    Posts
    12
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    Yep but I would move that line upto where you call nextInt to make it clear as to what the code is doing.
    Would i need to call it multiple times then?
    Java Code:
    System.out.print("Room number: ");
    				whichRoom = myScanner.nextInt();
    				[B]myScanner.nextLine();[/B]
    				System.out.print("How Many Guests? ");
    				numGuests = myScanner.nextInt();
    				[B]myScanner.nextLine();[/B]
    				guestsIn[whichRoom] = numGuests;			
    				System.out.print("Do another? ");
    ...or just 1 time:

    Java Code:
    System.out.print("Room number: ");
    				whichRoom = myScanner.nextInt();
    				System.out.print("How Many Guests? ");
    				numGuests = myScanner.nextInt();
    				[B]myScanner.nextLine();[/B]
    				guestsIn[whichRoom] = numGuests;			
    				System.out.print("Do another? ");

  2. #22
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    10

    Default

    You would only have to clear the buffer after the last call to nextInt. If you type 4<enter>5<enter>, the first call to nextInt would read the 4 and leave <enter>5<enter>. The second call would read the 5, ignore everything in between and leave <enter> in the buffer.

  3. #23
    buildakicker is offline nOOb :)
    Join Date
    Jul 2011
    Posts
    12
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    You would only have to clear the buffer after the last call to nextInt. If you type 4<enter>5<enter>, the first call to nextInt would read the 4 and leave <enter>5<enter>. The second call would read the 5, ignore everything in between and leave <enter> in the buffer.
    AH! That explains it. Thanks so much for your time and to Norm also.

    I am just getting into Java, any advice or good resources you like, I'd love to check them out. After the dummies book, I am moving on to Headfirst Java.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 15
    Last Post: 01-13-2011, 07:28 PM
  2. java.lang.NullPointerException
    By peterhabe in forum New To Java
    Replies: 5
    Last Post: 08-27-2010, 08:43 PM
  3. java.lang.NullPointerException
    By Pombi in forum New To Java
    Replies: 6
    Last Post: 05-15-2010, 03:12 PM
  4. java.lang.NullPointerException
    By vasavi.singh in forum New To Java
    Replies: 1
    Last Post: 02-27-2009, 01:36 PM
  5. java.lang.NullPointerException
    By stevemcc in forum AWT / Swing
    Replies: 2
    Last Post: 02-08-2008, 10:01 AM

Tags for this Thread

Posting Permissions

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