// ComputeMean2.java // Compute and report the mean of the integers // that the user is prompted to provide import java.util.Scanner; public class ComputeMean2 { public static void main(String[] args) { // create a scanner Scanner sc = new Scanner(System.in); // prompt user for number of scores System.out.print("How many scores? "); int n = sc.nextInt(); // create an array in which to store the scores // (not actually necessary for this problem, but useful // to see how to declare and use our own array) int[] scores = new int[n]; // prompt user for the n scores themselves for (int i = 0; i < n; i++) { System.out.print("Enter score #" + (i+1) + ": "); scores[i] = sc.nextInt(); } // add up all the scores double sum = 0; for (int i = 0; i < n; i++) { sum += scores[i]; } // compute and print mean System.out.println("Mean is " + sum / n); } }