GradesArray

/** * Has an array of grades and finds the low, high, and average of the grades. * * @Laura * @1.0 */ public class GradeArray { public static void main (String[] args) { double[] grades = new double[20]; //initializing variables and arrays double low = 100; double high = 0; double sum = 0; double avg = 0; for (int i = 0; i < 20; i++) { //for loop to enter random numbers into grades array int rand = (int)(Math.random() * 40 + 60); //generates random numbers grades[i] = rand; //adds random number generated to grades array } for (int j = 0; j < 20; j++) { //for loop to check for high and low values double temp = grades[j]; sum += temp; //adds each grade together if (grades[j] < low) { //checks for low values low = grades[j]; } if (grades[j] > high) { //checks for high values high = grades[j]; } } avg = sum/20.0; //calculate average System.out.println("The lowest grade was " + low + "."); //outputs values System.out.println("The highest grade was " + high + "."); System.out.println("The average was " + avg + "."); } }

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.