Jordan Collins wrote:Okay, so... I probably overused the != -99 a bit, but oh well...
I'm afraid both you and wei have fallen into the trap that many beginners do: not knowing when to
StopCoding (←click).
You can't just expect the solution to magically appear, you need to
understand the problem first; so if the first thing you do is to sit down and start writing Java code, the chances are your solution will be poorly written (and probably
over-written).
Think of it as a kid's game with wooden blocks with numbers on. You hand the kid the blocks, one at a time, and s/he has to keep the the lowest and highest of the ones s/he's been given until you stop. What does the kid have to do?
Write it down in English (or your native language), because
that's the essence of the problem. All the other stuff about Scanners, and loops, and conditions, and how to input numbers, is all eyewash; and it's a
distraction. You definitely need it to get your program working properly, but it's not what makes
this program/problem unique.
My advice: Forget about this particular problem for the moment, and familiarise yourself with the business of using Scanner.
Write some
test programs that take
one value, or 3, or 10, or any number until you enter "quit" (or -99); and for the moment,
don't worry about what you're going to do with those values; just print them out, so you can see they were received OK.
Make sure you can get strings, and numbers, and single characters, or anything else you can think of. Try and use as many of the "
next..." and "
hasNext..." methods as you can, so that you really understand the API.
The reason? Because user input is something you have to do A LOT - at least when you're starting out - and it's tricky and fiddly.
But it almost always follows the same
patterns:
Input 3 numbers (or 5, or 10).Input customers names until the user types "quit".Input values until one of them matches something previously stored in the program....
and getting a handle on how to use Scanner properly really gives you a good head start on how to write all sorts of programs like that.
And believe me, by the time you've become an "expert" in using Scanner, the business of "min" and "max" will be a walk in the park.
HIH
Winston