Verityprep
Question Bank · Unit 4

AP® Computer Science A Data Collections Practice Questions

Work through AP Computer Science A practice questions on Data Collections, then check each answer against a worked solution.

Free · no sign-up Open questions need no account. Sign up or log in to open the rest.

Subtopic: 2D Arrays Clear filter

Questions 191–195 of 195
  1. 191
  2. 192
  3. 193
  4. 194
  5. 195

Question 191

Multiple choice 2D Arrays
Consider the following code segment. int[][] m = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }; int sum = 0; for (int r = 0; r < m.length;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 192

Multiple choice 2D Arrays

Consider the following code segment.

int[][] grid = {
    {1, 2, 3},
    {4, 5, 6},
    {7, 8, 9}
};

int sum = 0;

for (int r = 0; r < grid.length; r++)
{
    for (int c = 0; c < grid[0].length; c++)
    {
        if (r + c == 2)
        {
            sum = sum + grid[r][c];
        }
        else if (r == c)
        {
            sum = sum - grid[r][c];
        }
    }
}

What is the value of sum after the loops?

Pick an answer, then check it. The solution opens in a window.

Question 193

Free response 2D Arrays
The DeliveryWindow class stores the number of packages delivered during each recorded hour of a day. public class DeliveryWindow { private int[] packages;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 194

Free response 2D Arrays
An OrchardGrid object stores fruit counts for trees arranged in a rectangular grid. Each entry in fruit is the number of fruits currently on one tree. public…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 195

Free response 2D Arrays
This question involves analyzing an orchard of apples to determine how many apple pies can be baked. The orchard is represented as a two-dimensional array of…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 191 of 195
Page 20 of 20