Informal Code Analysis (Loop Tracing)

AP Computer Science A· difficulty 4/5

What does this print?

<code>int x = 0; for (int i = 0; i < 5; i++); x++; System.out.println(x); </code></pre>

  • A

    0

  • B

    5

  • C

    Infinite

  • D

    1

    check_circle

Explanation

Trailing <code>;</code> ends the for loop. <code>x++;</code> runs once, after the loop.

Want 10 more like this — adaptive to your weak spots?

Related questions