Nested Iteration

AP Computer Science A· difficulty 4/5

What does this print?

<code>for (int i = 1; i <= 2; i++) for (int j = 1; j <= 3; j++) System.out.print(i*j + " "); </code></pre>

  • A

    1 2 3 4 5 6

  • B

    1 2 3 1 2 3

  • C

    1 2 3 2 4 6

    check_circle
  • D

    1 4 9

Explanation

i=1: j=1,2,3 → 1 2 3; i=2: j=1,2,3 → 2 4 6.

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

Related questions