AP® Computer Science A

Free Version

Upgrade subject to access all content

Easy

Negating Boolean Values Within a For Loop

APCSA-KVVWKP

Consider the following code.

boolean onOffSwitch = true;
for (int i=1; i<10; i++)
{
    if (onOffSwitch)
    {
        if (i%3==0)
            onOffSwitch = !onOffSwitch;
        else
            i++;
    }
    else
    {
        if (i%2==0)
        {
            i+=2;
            onOffSwitch = !onOffSwitch;
        }
    }
    System.out.print(onOffSwitch + " ");
}

What is printed as a result of executing the code?

A

true true false true true true false

B

true false true true false

C

true false true true true false

D

false false true true true

E

true false false true true