AP Computer Science Amediummcq1 pt

Which code correctly visits every element of int[][] grid?

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

Explanation

Core Concept

The outer loop yields rows and the inner yields values.

Correct Answer

Afor (int[] row : grid) for (int v : row)

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 →