?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Easy

Debugging Code: Array Calculate Bowling Average

APCSA-HEBYB6

Consider the following method.

/**
 * Calculate the average bowling score.
 * Array may not be full of scores (a score of zero
 * is not a valid score)
 * Precondition: valid scores are between 10-300
 */
public static double calcBowlingAvg(int[] scores)
{
    double sum=0;
    for (int i=0; i<scores.length; i++)
    {
        sum+=scores[i];
    }
    return sum/scores.length;
}

Which of the following arrays would this method calculate the correct bowling average for?

I.   int[] scores = {100, 120, 110, 105, 100};
II.  int[] scores = {141, 150, 110, 0, 0};
III. int[] scores = {97, 50, 130, 105, 0};
A

I only.

B

II only.

C

III only.

D

I and III only.

E

I, II, and III.