• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to get greatest and smallest?  RSS feed

 
Amin Shirzad
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to write a program which gets 10 scores and prints out: sum of them, average of them, the greatest scores and the smallest scrore.
I've written this much, but I don't know how to write to get greatest and smallest. I'll be thankful if you help me.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forget about java.  If i handed you a slip of paper with ten numbers written on it, how would you, personally, find the largest?
 
Glenn Jayasuriya
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the same loop to iterate over the array.
Use comparators like <,> etc
Keep track of the max and min value with a variable
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!