Traversing 2D Arrays

AP Computer Science A· difficulty 4/5

public static int run() {
    int[][] m = {{1,2},{3,4},{5,6}};
    for (int i = 0; i < m.length; i++)
        for (int j = 0; j < m[0].length; j++)
            m[i][j] *= (i + j);
    return m[2][1];
}
// Call: System.out.println(run());

What is printed?

  • A

    15

  • B

    12

  • C

    18

    check_circle
  • D

    6

Explanation

m[2][1] = 6 * (2+1) = 6 * 3 = 18.

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

Related questions