Score Average Calculator
static double getScoreAverage (double [] scores)
{
double total = 0.0;
for (int i = 0; i < scores.length; i++)
{
total = total + scores[i];
}
return scores.length == 0 ? 0 : total / scores.length;
}
//Scanner input = new Scanner(system.in);
//System.out.print("What is the total number of scores do you have?:");
//int studentCount = intput.nextint();
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.println("How many scores do you need to enter?");
int scoreCount = input.nextInt();
double [] scores = new double[scoreCount];
for (int i = 0; i < scoreCount; i++)
{
System.out.println("Please enter score: ");
double score = input.nextDouble();
scores[i] = score;
System.out.println(score);
}
// double [] scores = new double[] { 100, 92, 78, 32, 100 };
System.out.println("Average score is: " + getScoreAverage(scores));