AP Computer Science Amediummcq1 pt

Which loop visits every element of grid in row-major order?

A.for (int r = 0; r < grid.length; r++) for (int c = 0; c < grid[0].length; c++)
B.for (int c = 0; c < grid[0].length; c++) for (int r = 0; r < grid.length; r++)
C.for (int r = 0; r < grid.length; r++)
D.for (int r = 0; r ≤ grid.length; r++)

Explanation

Core Concept

The row loop is outside.

Correct Answer

Afor (int r = 0; r < grid.length; r++) for (int c = 0; c < grid[0].length; c++)

More Unit 8: 2D Array practice questions

Try a random question →

Practice more AP Computer Science A questions with full explanations

Practice Unit 8: 2D Array Questions →