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:

# Finding Min and Max out of several different user inputs.

Johnny Wayne
Greenhorn
Posts: 19
This is what I have so far. I need to print the minimum and maximum values in the console.

Carey Brown
Saloon Keeper
Posts: 3329
46
Have you studied arrays and loops yet? They would clean up your cut-n-past code quite a bit.
In the mean time this is the general approach.

Campbell Ritchie
Marshal
Posts: 56600
172
Calculate sum and maximum as you go through the loop in similar fashion. You may not need the twelve inputs thereafter. Find out about the ?: operator which can make the code for min and max much more concise.

Johnny Wayne
Greenhorn
Posts: 19
How would I use a loop to ask the user for each months utility bill instead of using an array or copy and paste format like I have?

Carey Brown
Saloon Keeper
Posts: 3329
46

You need to use both an array and a loop.

Johnny Wayne
Greenhorn
Posts: 19
and then I would insert the previous code you posted to find min and max?

Carey Brown
Saloon Keeper
Posts: 3329
46
Johnny Wayne wrote:and then I would insert the previous code you posted to find min and max?
You'd have to put the min/max logic after line 5 or in its own loop.

Johnny Wayne
Greenhorn
Posts: 19
Carey Brown wrote:
Johnny Wayne wrote:and then I would insert the previous code you posted to find min and max?
You'd have to put the min/max logic after line 5 or in its own loop.

Thank you very much

Carey Brown
Saloon Keeper
Posts: 3329
46
Remember that array indices are zero based so for you that would be indexes 0 through 11, hence the '(i+1)' in line 4.

 With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.