?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Easy

Array Algorithm of Salaries

APCSA-JXSGPL

Consider the following method.

// only salaries that are more than $0 are considered valid salaries
public static double methodB(int[] salaries)
{
    int count = 0;
    double sum = 0;

    for (int salary : salaries)
    {
        sum+=salary;
        if (salary>0)
            count++;
    }
    if (count>0)
        return sum/count;
    return 0;
}

What does this method return?

A

the sum of all the salaries in the array

B

the average of all salaries in the array

C

the count of how many valid salaries are in the array

D

the average of all valid salaries in the array

E

the sum of all valid salaries in the array