Last Friday in our AP Computer Science class (which is where we're learning Java), my teacher gave us a sample from last year's AP exam. The first question confused almost everyone.
It had a code segment:
CODE
for (int k = 0; k < 20; k = k + 2)
{
if (k % 3 == 1)
System.out.print(k + " ");
}
Then we had to determine what would be outputted. Here were the choices:
A) 4 16
B) 4 10 16
C) 0 6 12 18
D) 1 4 7 10 13 16 19
E) 0 2 4 6 8 10 12 14 16 18
Everyone (who wasn't too lazy to work it out) chose D. Which, according to the answer key, was wrong. B was the correct answer, but it had no explanation. This isn't helping me, and it's bringing me closer to giving up on learning Java. Anyone have an explanation?