Skip to main content

Unit 4 · Data Collections

2D Array Traversal

2D Array Traversal MCQ Practice

Question 1 of 15

Answered 0 of 15

Choose one answer.

What is printed by the following code segment?

public class GridArrayTraversalContext
{
    public static void runExample()
    {
        int[][] g = {{1, 2}, {3, 4}};
        int s = 0;
        for (int r = 0; r < g.length; r++)
        {
            for (int c = 0; c < g[r].length; c++)
            {
                s += g[r][c];
            }
        }
        System.out.print(s);
    }

    public static void main(String[] args)
    {
        runExample();
    }
}
Choose one answer.