Grade Program: Arrays

/** *Charlotte Weisman *B Block CompSci *10/10/17 *Grade Program: Arrays */ import java.util.*; public class gradeArrays{ public static void main(String[] args){ double[] grades = new double[20]; double high = 0; double low = 100; double total = 0; for(int i = 0; i < 20; i++){//create 20 random grades grades Random rand = new Random(); double randomNum = 60.0 + (100.0 - 60.0) * rand.nextDouble(); grades[i]=randomNum;//where randomNum is a int between 60 and 100 } System.out.println("Grades: " + Arrays.toString(grades)); for(int j = 0; j < 20; j++){//determine high and low grades if(grades[j] > high){ high = grades[j]; } if(grades[j] < low){ low = grades[j]; } total += grades[j]; } double avg = total / 20.0;//average all grades System.out.println("high: " + high); System.out.println("low: " + low); System.out.println("average: " + avg); } }
Charlotte Weisman
B Block CS
Arrays practice

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.