Scanner has only been around since version 1.5. People who learnt prior to 1.5 used BufferedReader. Old habits die hard sometimes.
Printable View
Scanner has only been around since version 1.5. People who learnt prior to 1.5 used BufferedReader. Old habits die hard sometimes.
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
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
Code:declare variables for galons, miles, totalGalons, totalMiles
loop
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
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.