File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Programming Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Programming Problem" Watch "Programming Problem" New topic
Author

Programming Problem

Irene Wang
Greenhorn

Joined: Apr 14, 2007
Posts: 3
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

Joined: Feb 23, 2007
Posts: 1561
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

Joined: Apr 14, 2007
Posts: 3
No can do, because we "supposedly" haven't and aren't supposed to have learned anything about arrays or loops yet.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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

Joined: Apr 14, 2007
Posts: 3
Oh, ok. I see. Thanks a bunch!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Programming Problem