AP® Computer Science A

Free Version

Upgrade subject to access all content

Easy

For Each Loop for an Array of Integers

APCSA-EBTYNB

Consider the following code segment.

int[] nums = /* nums points to a valid array of integers */
int count=0;

// Count array elements > 20
for (int e : nums)
{
    if (nums[e] > 20)
        count++;
}

Which of the following statements is TRUE after executing this code segment?

A

The variable count will contain the number of integers that are greater than 20 in the array .

B

The variable count will be greater than 0.

C

The code would throw an error if nums contains {29, 10, 52, 36, 4}.

D

The code would throw an error if nums contains {2, 0, 3, 1}.

E

The code will always throw an error.