?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

Count AP Classes in a String Array of Subjects

APCSA-JNEAKV

Assume that the subjects array contains a list of all the classes a student is taking during his/her senior year, in the order (1st period, 2nd period, etc.) that the student attends the classes during the school day. The student attends classes during periods 1-6.

In which situations will the following code correctly count the number of AP classes the student is taking? Note: Only AP classes contain "AP" in the subject name.

public static int numberOfAPClasses(String[] subjects)
{
    int x=0, count=0;
    while(subjects[x].indexOf("AP")>=0  && x<subjects.length)
    {
        count++;
        x++;
    }
    return count;
 }

I. The student takes three AP classes during the first 3 periods of the day.
II. The student takes one AP class during the final period of the day.
III. The student only takes AP classes
IV. The student takes no AP classes.

A

I and III only.

B

III and IV only.

C

I and IV only.

D

I, III, and IV only.

E

II, III, and IV only.