Traversing 2D Arrays

AP Computer Science A· difficulty 3/5

Traverse all elements of <code>int[][] m</code> row-by-row:

  • A

    for (int j = 0; j < m[0].length; j++) for (int i = 0; i < m.length; i++) ...

  • B

    for-each on m only

  • C

    for (int i = 0; i < m.length; i++) for (int j = 0; j < m[i].length; j++) ...

    check_circle
  • D

    for (int i = 0; i < m.length; i++)

Explanation

Standard pattern: outer rows, inner columns.

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

Related questions