• Post Reply Bookmark Topic Watch Topic
  • New Topic

Finding Min and Max out of several different user inputs.  RSS feed

 
Johnny Wayne
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You need to use both an array and a loop.
 
Johnny Wayne
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and then I would insert the previous code you posted to find min and max?
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!