/*
* Sejin Park
* Finds average, high, and low of array of random grades.
* 10/06/17
*/
public class GradesArray {
public static void main(String[] args){
double[] grades = new double[20];
int newGrade;
int highestGrade = 0;
int lowestGrade = 100;
int average = 0;
for(int i=0; i< 20; i++){//runs 20 times
newGrade = (int)(Math.random() * ((100-60) +1)) + 60;
grades[i] = newGrade;//places grade into the array
if(newGrade>highestGrade)
highestGrade = newGrade;
if(lowestGrade>newGrade)
lowestGrade = newGrade;
average += newGrade;
}
average = average/20;
System.out.println("highest grade: " + highestGrade + " lowest grade: " + lowestGrade + " average: " + average);
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.