Arrays

import java.util.*; public class GradeArrays { public static void main(String[] args){ double[] grades = new double[20]; System.out.println("The grades are: \n"); for (int i = 0; i<20; i++) { int randomNumber = (int) (Math.random( ) * (100 - 60) + 1) + 60; grades[i] = randomNumber; System.out.println(grades[i] + "%"); } 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; } if (value2 < low){ low = value2; } sum += grades[i]; average = sum / 20; } System.out.println("The high grade is: " + high + "%"); System.out.println("The low grade is: " + low + "%"); System.out.println("The average grade is: " + 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.