?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

Array Initialization: Equivalent Code

APCSA-EAELNK

The code segment

int[] x = {5,10,15,20,25};

is equivalent to which of the following?

I.

int[] x = new int[5];
for (int i = 0; i < x.length; i+=5)
     x[i] = i;

II.

int[] x = new int[5];
for (int i = x.length; i >= 0; i--)
     x[i] = i*5 + 5;

III.

int[] x = new int[5];
for (int i = x.length-1; i >= 0; i--)
     x[i] = 5*(i + 1);

IV.

int[] x = new int[5];
for (int i : x)
{
     i*=5;
     i+=5;
}
A

I only.

B

III only.

C

II and III only.

D

I, II, and III only.

E

I, II, III, and IV.