Grade Array

/* * Sejin Park * Finds average, high, and low of array of random grades. * 10/06/17 */ public class GradesArray { public static void main(String[] args){ int[] grades = new int[20]; int newGrade; int highestGrade = 0; int lowestGrade = 100; int average = 0; for(int i=0; i< 20; i++){//runs 20 times newGrade = (int)(Math.random() * ((100-60) +1)) + 60; grades[i] = newGrade;//places grade into the array } for(int i=0; i<20; i++){ if(grades[i]>highestGrade) highestGrade = grades[i]; if(lowestGrade>grades[i]) lowestGrade = grades[i]; average += grades[i]; } average = average/20; System.out.println("highest grade: " + highestGrade + " lowest grade: " + lowestGrade + " average: " + 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.