Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Programming Problem

 
Irene Wang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm in an Introduction to Java course online. One of my recent assignments is this:

Ask and get 13 scores (integers between and including 0 and 100).
Display the arithmetic mean (average) on one line. Display the number of
As, Bs, etc. using a 90, 80, 70, etc. grading scale. Display the range of
the numbers as well. Range is defined as the largest number minus the
smallest number plus one.

I've got everything down except for the last part about the range. I don't get how to find out which integers are the largest and smallest without going through a bunch of ifs, else ifs, and elses. I know there's a way using array, but we haven't learned that yet. Is there any other method? I'm going nuts here.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you have int variables for lowest and highest and initialize the lowest at 100, the highest at 0, loop through and replace w/ a number in the array if lower or higher?
 
Irene Wang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No can do, because we "supposedly" haven't and aren't supposed to have learned anything about arrays or loops yet.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's fine, no need for an array or loop. You can still do the same thing as the numbers are being entered: replace a lowest or a highest variable value with the entered value if lower or higher than the previous occupants.
[ April 14, 2007: Message edited by: pete stein ]
 
Irene Wang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, ok. I see. Thanks a bunch!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic