?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

Sequential Search Used to Count Matches in an ArrayList of Ints

APCSA-DOEAYN

The following method counts the number of times a value (represented by key) appears as an element in an ArrayList named nums.

public static int search(ArrayList<Integer> nums, int key)
{
    int j = 0;
    for ( /*missing code*/ )
        if (key == x)
            j++;
    return j;
}

Which of the following should replace /*missing code*/?

A
int x : nums
B
int x : nums.get(i)
C
int x = 0; x < nums.length; x++
D
int x = 0; x
E
int x = nums.size() - 1; x >= 0; x--