Pat Gareau

Ranch Hand

Posts: 30

posted 5 months ago

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?

posted 5 months ago

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 ?

Do you have knowledge about using arrays and collections ?

I agree. Here's the better link: Salvin.in

Campbell Ritchie

Marshal

Posts: 56600

172

posted 5 months ago

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 <.

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 <.

posted 5 months ago

Do you know about

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.

`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.

All things are lawful, but not all things are profitable.

It is sorta covered in the JavaRanch Style Guide. |