?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

While True Loop That Uses Modulus Arithmetic

APCSA-VKPEYE

Consider the following code segment.

int a=0, b=0;
while (true)
{
    if (a%3==0)
        b++;
    if (b>2)
        break;
    a++;
}
System.out.println(a*b);

What is printed as a result of executing the code segment?

A

6

B

18

C

21

D

27

E

The code is stuck in an infinite loop.