2D Arrays: Creation and Access

AP Computer Science A· difficulty 3/5

int[][] m = {{1, 2}, {3, 4}};
for (int r = 0; r < m.length; r++) {
    for (int c = 0; c < m[r].length; c++) {
        m[r][c] *= 2;
    }
}
System.out.println(m[1][1]);

What is printed?

  • A

    4

  • B

    16

  • C

    8

    check_circle
  • D

    6

Explanation

Each element is doubled. m[1][1] was 4, becomes 8.

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

Related questions