GradeArray

import java.util.*; import java.util.Scanner; /** * Charlie Barton * Date: On time * Creates an array with random number and finds the: high, low, and average. * */ public class gradearrays { public static void main(String[] args) { int[] grades = new int[20]; int max = 100; int min = 60; int high = 0; int low = 100; int average = 0; for(int i = 0; i <grades.length; i++){ int randNumber = (int)(Math.random() * ((max - min) + 1)) + min; grades[i] = randNumber; System.out.print(grades[i] + " "); } for(int i = 0; i <grades.length; i++){ if(grades[i] > high) high = grades[i]; if(grades[i] < low) low = grades[i]; average += grades[i]; } System.out.println("Average grade: " + average/20); System.out.println("Highest grade: " + high); System.out.println("Lowest grade: " + low); } }

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.