Traversing 2D Arrays

AP Computer Science A· difficulty 4/5

What does this print for m={{1,2},{3,4}}?

<code>for (int[] row : m) { for (int x : row) System.out.print(x + " "); System.out.println(); } </code></pre>

  • A

    1 2 3 4 (one line)

  • B

    1 2\n3 4

    check_circle
  • C

    1234

  • D

    1\n2\n3\n4

Explanation

Each row prints its elements then a newline.

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

Related questions