Limited access

Upgrade to access all content for this subject

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)
    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.


I and III only.


III and IV only.


I and IV only.


I, III, and IV only.


II, III, and IV only.

Select an assignment template