View Single Post
  #2 (permalink)  
Old 03-06-2008, 08:01 PM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,147
hardwired is on a distinguished road
Code:
public class ArrayOfScores { public static void main(String[] args) { int[] scores = { 3, 7, 2, 5, 4 }; int smallest, highest, temp, total = 0; double average = 0.0; //find the lowest score smallest = Integer.MAX_VALUE; for (int i = 0; i < scores.length; i++) if (scores[i] < smallest) smallest = scores[i]; System.out.println("\nThe lowest score is : " + smallest); //find the highest score highest = -Integer.MAX_VALUE; for (int i = 0; i < scores.length; i++) if (scores[i] > highest) highest = scores[i]; System.out.println("\nThe highest score is : " + highest); //find the average score for (int i = 0; i < scores.length; i++) total = total + scores[i]; average = (double)total/scores.length; System.out.println("\nThe average score is : " + average); } }
Reply With Quote