Traversing 2D Arrays

AP Computer Science A· difficulty 4/5

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

What is printed?

  • A

    6

  • B

    8

    check_circle
  • C

    5

  • D

    7

Explanation

Max value in matrix is 8.

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

Related questions