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.
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?
Joined: Apr 14, 2007
No can do, because we "supposedly" haven't and aren't supposed to have learned anything about arrays or loops yet.
Joined: Feb 23, 2007
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 ]