zuai-logo
zuai-logo
  1. AP Computer Science A
FlashcardFlashcardStudy GuideStudy GuideQuestion BankQuestion Bank

2D Arrays in AP Computer Science A

Question 1
Computer Science AAPExam Style
1 mark

Which of the following is the correct way to declare and initialize a rectangular 2D array of integers with 3 rows and 4 columns?

Question 2
Computer Science AAPExam Style
1 mark

Consider the following code snippet:

java
int[][] matrix = new int[2][3];
matrix[0][0] = 1;
matrix[0][1] = 2;
matrix[0][2] = 3;
matrix[1][0] = 4;
matrix[1][1] = 5;
matrix[1][2] = 6;

How are the elements of matrix stored in memory...

Question 3
Computer Science AAPExam Style
1 mark

Given the following initialization of a 2D array, what is the value of array[1][2]?

String[][] array = {{"apple", "banana", "cherry"}, {"date", "elderberry", "fig"}};

Question 4
Computer Science AAPExam Style
1 mark

Consider the following 2D array:

java
int[][] grid = {{1, 2, 3}, {4, 5, 6}};

Which representation best describes grid in memory?

Question 5
Computer Science AAPExam Style
1 mark

What is the correct way to access the element in the second row and third column of the following 2D array?

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

Question 6
Computer Science AAPExam Style
1 mark

Consider the following code snippet:

java
int[][] values = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int sum = 0;
for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 3; j++) {
        sum += values[i][j];
    }
}
System.out.println(sum);

...

Question 7
Computer Science AAPExam Style
1 mark

What will happen when the following code is executed?

java
int[][] matrix = new int[3][4];
System.out.println(matrix[3][0]);
Feedback stars icon

How are we doing?

Give us your feedback and let us know how we can improve

Question 8
Computer Science AAPExam Style
1 mark

Consider the following 2D array:

java
int[][] arr = {{1, 2, 3}, {4, 5, 6}};

What is the value of arr[0].length?

Question 9
Computer Science AAPExam Style
1 mark

How many rows does the following 2D array have?

int[][] myArray = new int[5][10];

Question 10
Computer Science AAPExam Style
1 mark

Given the following code:

java
int[][] matrix = new int[2][2];
matrix[0][0] = 1;
matrix[0][1] = 2;
matrix[1][0] = 3;
matrix[1][1] = 4;
int[] arr = matrix[0];
arr[0] = 5;
System.out.println(matrix[0][0]);

What is printed to the cons...