import java.util.*;
public class GradeArrays
{
public static void main(String[] args){
double[] grades = new double[20];//array of 20 different grades
System.out.println("The grades are: \n");
for (int i = 0; i<20; i++) {
int randomNumber = (int) (Math.random( ) * (100 - 60) + 1) + 60;//random number generator
grades[i] = randomNumber;
System.out.println(grades[i] + "%");
}//end of first for loop
double high = 0.0;
double low = 100.0;
double sum = 0.0;
double average = 0.0;
for(int i = 0; i < 20; i++){
double value = grades[i];
double value2 = grades[i];
if (value > high){
high = value;//finds highest grade
}
if (value2 < low){
low = value2;//find lowest grade
}
sum += grades[i];
average = sum / 20;//average of all grades
}//end of 2nd for loop
System.out.println("\nThe highest grade is: " + high + "%");
System.out.println("The lowest grade is: " + low + "%");
System.out.println("The average grade is: " + average + "%");
}//end of method
}//end of class
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.