• Post Reply Bookmark Topic Watch Topic
  • New Topic

Min and max number and user input  RSS feed

 
Pat Gareau
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!