?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

For Loop Printing Equivalency

APCSA-WFL4U4

Consider the output of the following code segment.

for (int i=1; i<=30; i++)
    if (0 == i%5)
        System.out.println(i); 

Which of the following code segments has the same output?

A
for (int i=0; i<=30; i++)
    if ((i+1)%5 == 0)
        System.out.println(i);
B
for (int i=30; i >0; i--)
    if (0 == i%5)
        System.out.println(i);
C
for (int i=1; i<=30; i+=5)
    System.out.println(i);
D
for (int i=5; i<=32; i+=5)
    System.out.println(i);
E
for (int i=1; i<=30; i++)
    System.out.println(i*5);