programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Min and max number and user input

Pat Gareau
Ranch Hand
Posts: 30
Hello, I am having an issue with writing some code. I need to have a list of 100 numbers in total. I need to input them one at a time and determine the smallest number and the greatest number. I know how to loop numbers together but I dont know how to input them individually then know which is the lower or higher number. How can I go about ding this?

salvin francis
Bartender
Posts: 1664
37
You obviously need to first accept all 100 numbers from the user and only then the max and min numbers can be determined.
Do you have knowledge about using arrays and collections ?

Campbell Ritchie
Marshal
Posts: 56600
172
No, you can work out the largest and smallest numbers from a hundred without recording any of the other numbers.

Start by working out how to do that by hand. Alternatively, get a set of numbered balls (old‑fashioned bingo/lotto balls), pull them out of the bag, look for the largest and immediately put the used ball aside. Note how you do it by hand and use the same algorithm to find the largest. Once you have worked out how to find the largest, finding the smallest will use a very similar algorithm except that you swap > and <.

Knute Snortum
Sheriff
Posts: 4289
127
Do you know about while and do/while loops?  The while take a condition, just like an if.

In your case you want to loop while fewer than 100 numbers have been entered.  So you'll need a counter variable and you'll need to test that counter in the while loop condition.  Make sense?  Try it and show use what you come up with.

 It is sorta covered in the JavaRanch Style Guide.