Page 2 of 2 FirstFirst 12
Results 21 to 24 of 24
Like Tree10Likes

Thread: Loop problems

  1. #21
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Rep Power


    Scanner has only been around since version 1.5. People who learnt prior to 1.5 used BufferedReader. Old habits die hard sometimes.
    tnrh1 likes this.

  2. #22
    amzers is offline Member
    Join Date
    Dec 2010
    Rep Power


    nahhh the right code above was just a dummy,i was adding up things to see if it works...
    i just want to get the thought of it not just the tank program thingy :)

    i dont really know how to use scanner,they havent teached us on our institute on how scanner works so im using bufferedreader
    JeffGrigg likes this.

  3. #23
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Richmond, Virginia
    Blog Entries
    Rep Power


    If you don't know how to use a scanner, continue with what you do know. They work very similarly though. I'd be hesitant to just hack code together. Just because it works, doesn't mean it's necessarily a good thing. You should be able to understand what the code is doing and how, rather than just throwing pieces together until it works.

    Here is more pseudo-code
    Java Code:
    declare variables for galons, miles, totalGalons, totalMiles
      get input
      if(input is sentinel)
        exit loop
      end if
      get more input
      add both inputs to total count
      print mpg this pass through
    end loop
    print mpg total
    JeffGrigg likes this.

  4. #24
    JeffGrigg is offline Member
    Join Date
    Aug 2011
    Rep Power


    Scanner is nice. I see that a lot of schools are using it. It's a convenient way to get formatted input. But it can have unintended side effects.

    I never use it in production.

    If the instructor suggests using it, then it's a good thing to use. If the instructor didn't mention it, then it might be better not to use it. But, of course, if you find that it meets your needs, then please feel free.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Problems with While loop execution
    By Kevinius in forum New To Java
    Replies: 12
    Last Post: 03-03-2011, 08:35 AM
  2. Try catch loop problems :'(
    By Romally in forum New To Java
    Replies: 7
    Last Post: 11-17-2010, 09:15 PM
  3. Loop problems
    By jim01 in forum New To Java
    Replies: 3
    Last Post: 10-18-2010, 12:49 AM
  4. Newbie having problems with for loop
    By Dannii in forum New To Java
    Replies: 4
    Last Post: 04-13-2009, 11:52 PM
  5. Problems with while loop
    By Albert in forum New To Java
    Replies: 2
    Last Post: 07-04-2007, 07:19 AM

Posting Permissions

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