{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

GymnasticsMean - Calculates the mean of a double...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * File: GymnasticsMean.java * -------------------------- * This file reads in an array of scores and computes the * average. * * Author: CS1MD3, Nov. 2008 */ import acm.program.*; public class GymnasticsMean extends ConsoleProgram { public void run() { double[] scores = new double[N_JUDGES]; for (int i = 1; i <= N_JUDGES; i++) { scores[i - 1] = readDouble("Enter score for judge " + i + ": "); } println("The average score is " + mean(scores));
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } /** * Calculates the mean of a double array * @param array An array of doubles * @return The mean of the array */ public double mean(double array) { int n = array.length; double total = 0; for (int i = 0; i < n; i++) { total += array[i]; } return total / n; } /* Private constant */ private static final int N_JUDGES = 5; /* number of judges */ }...
View Full Document

{[ snackBarMessage ]}