2D Array Traversals - AP Computer Science A
Card 1 of 30
What is the result of 'array[2].length' if array has 3 rows, unequal columns?
What is the result of 'array[2].length' if array has 3 rows, unequal columns?
Tap to reveal answer
Length of third row. Returns column count specifically for row at index 2.
Length of third row. Returns column count specifically for row at index 2.
← Didn't Know|Knew It →
Identify the error: 'int[][] array = { {1, 2}, {3, 4, 5} };'
Identify the error: 'int[][] array = { {1, 2}, {3, 4, 5} };'
Tap to reveal answer
Array is jagged, not rectangular. Rows have different lengths, creating irregular structure.
Array is jagged, not rectangular. Rows have different lengths, creating irregular structure.
← Didn't Know|Knew It →
What does 'array.length * array[0].length' compute for a 2D array?
What does 'array.length * array[0].length' compute for a 2D array?
Tap to reveal answer
Total number of elements. Multiplies rows by columns for rectangular arrays.
Total number of elements. Multiplies rows by columns for rectangular arrays.
← Didn't Know|Knew It →
What is the type of elements in 'int[][] array = new int[2][3];'?
What is the type of elements in 'int[][] array = new int[2][3];'?
Tap to reveal answer
int. Declaration specifies integer as the element type.
int. Declaration specifies integer as the element type.
← Didn't Know|Knew It →
What is the syntax to declare a 2D array with specific values?
What is the syntax to declare a 2D array with specific values?
Tap to reveal answer
int[][] array = { {1, 2}, {3, 4} };. Initialization syntax using nested braces for values.
int[][] array = { {1, 2}, {3, 4} };. Initialization syntax using nested braces for values.
← Didn't Know|Knew It →
What is the initial value of 'array[i][j]' after 'int[][] array = new int[2][2];'?
What is the initial value of 'array[i][j]' after 'int[][] array = new int[2][2];'?
Tap to reveal answer
- New integer arrays initialize all elements to zero.
- New integer arrays initialize all elements to zero.
← Didn't Know|Knew It →
Identify the action: 'for (int[] row : array) { for (int elem : row) { sum += elem; } }'
Identify the action: 'for (int[] row : array) { for (int elem : row) { sum += elem; } }'
Tap to reveal answer
Sum all elements in 2D array. Enhanced for-loops accumulate all array element values.
Sum all elements in 2D array. Enhanced for-loops accumulate all array element values.
← Didn't Know|Knew It →
Which keyword is used to create a new 2D array object in Java?
Which keyword is used to create a new 2D array object in Java?
Tap to reveal answer
new. Essential keyword for creating array objects in memory.
new. Essential keyword for creating array objects in memory.
← Didn't Know|Knew It →
What exception is thrown by accessing an invalid 2D array index?
What exception is thrown by accessing an invalid 2D array index?
Tap to reveal answer
ArrayIndexOutOfBoundsException. Standard runtime exception for bounds violations.
ArrayIndexOutOfBoundsException. Standard runtime exception for bounds violations.
← Didn't Know|Knew It →
What does 'int[][] array = new int[3][];' initialize?
What does 'int[][] array = new int[3][];' initialize?
Tap to reveal answer
3 rows, undefined column sizes. Creates row array without specifying column dimensions.
3 rows, undefined column sizes. Creates row array without specifying column dimensions.
← Didn't Know|Knew It →
What is the function of 'array[0].length' in a 2D array?
What is the function of 'array[0].length' in a 2D array?
Tap to reveal answer
Number of columns in the first row. Returns column count for the first row only.
Number of columns in the first row. Returns column count for the first row only.
← Didn't Know|Knew It →
Identify the syntax error: 'int[][] array = new int()[3][3];'
Identify the syntax error: 'int[][] array = new int()[3][3];'
Tap to reveal answer
Correct: 'new int[3][3]'. Missing type specification between 'new' and brackets.
Correct: 'new int[3][3]'. Missing type specification between 'new' and brackets.
← Didn't Know|Knew It →
What is the result of 'array.length' in a 2D array?
What is the result of 'array.length' in a 2D array?
Tap to reveal answer
Number of rows. Returns the count of rows in the array.
Number of rows. Returns the count of rows in the array.
← Didn't Know|Knew It →
What is the purpose of nested loops in 2D array traversal?
What is the purpose of nested loops in 2D array traversal?
Tap to reveal answer
To iterate over all elements. Enables systematic access to every array element.
To iterate over all elements. Enables systematic access to every array element.
← Didn't Know|Knew It →
Find and correct the error: 'int[][] arr = new int[2][2]; arr[2][0] = 5;'
Find and correct the error: 'int[][] arr = new int[2][2]; arr[2][0] = 5;'
Tap to reveal answer
Correct: arr[1][0] = 5;. Index 2 is out of bounds for 2-row array.
Correct: arr[1][0] = 5;. Index 2 is out of bounds for 2-row array.
← Didn't Know|Knew It →
Find and correct the error: 'int[][] arr; arr[1][2] = 3;'
Find and correct the error: 'int[][] arr; arr[1][2] = 3;'
Tap to reveal answer
Correct: arr must be initialized before access. Array must be instantiated with 'new' before access.
Correct: arr must be initialized before access. Array must be instantiated with 'new' before access.
← Didn't Know|Knew It →
What operation is performed by 'array[i][j] += 1;' in a 2D array?
What operation is performed by 'array[i][j] += 1;' in a 2D array?
Tap to reveal answer
Increment element at array[i][j] by 1. Adds 1 to the current value at that position.
Increment element at array[i][j] by 1. Adds 1 to the current value at that position.
← Didn't Know|Knew It →
What is the typical structure of an outer loop for 2D arrays?
What is the typical structure of an outer loop for 2D arrays?
Tap to reveal answer
for (int i = 0; i < array.length; i++). Iterates through each row using array.length.
for (int i = 0; i < array.length; i++). Iterates through each row using array.length.
← Didn't Know|Knew It →
What is the term for accessing each element in a 2D array?
What is the term for accessing each element in a 2D array?
Tap to reveal answer
Traversal. The systematic process of visiting each element in order.
Traversal. The systematic process of visiting each element in order.
← Didn't Know|Knew It →
Identify the method to get the number of columns in a 2D array.
Identify the method to get the number of columns in a 2D array.
Tap to reveal answer
array[0].length. Accesses the length of the first row to get column count.
array[0].length. Accesses the length of the first row to get column count.
← Didn't Know|Knew It →
What is the syntax to declare a 2D array in Java?
What is the syntax to declare a 2D array in Java?
Tap to reveal answer
int[][] arrayName;. Standard declaration syntax using double brackets for 2D arrays.
int[][] arrayName;. Standard declaration syntax using double brackets for 2D arrays.
← Didn't Know|Knew It →
What is initialized first in a nested loop for 2D array traversal?
What is initialized first in a nested loop for 2D array traversal?
Tap to reveal answer
Row index. Outer loop variable controls row position first.
Row index. Outer loop variable controls row position first.
← Didn't Know|Knew It →
What is the type of elements in 'int[][] array = new int[2][3];'?
What is the type of elements in 'int[][] array = new int[2][3];'?
Tap to reveal answer
int. Declaration specifies integer as the element type.
int. Declaration specifies integer as the element type.
← Didn't Know|Knew It →
What does 'int[][] array = new int[3][];' initialize?
What does 'int[][] array = new int[3][];' initialize?
Tap to reveal answer
3 rows, undefined column sizes. Creates row array without specifying column dimensions.
3 rows, undefined column sizes. Creates row array without specifying column dimensions.
← Didn't Know|Knew It →
How do you assign a value to element at row 2, column 3 in array?
How do you assign a value to element at row 2, column 3 in array?
Tap to reveal answer
array[1][2] = value;. Arrays use zero-based indexing, so row 2 is index 1.
array[1][2] = value;. Arrays use zero-based indexing, so row 2 is index 1.
← Didn't Know|Knew It →
Identify the method to iterate over a 2D array using enhanced for-loops.
Identify the method to iterate over a 2D array using enhanced for-loops.
Tap to reveal answer
for (int[] row : array). Enhanced for-loop iterates over each row as an array.
for (int[] row : array). Enhanced for-loop iterates over each row as an array.
← Didn't Know|Knew It →
What is the result of accessing an out-of-bounds index in a 2D array?
What is the result of accessing an out-of-bounds index in a 2D array?
Tap to reveal answer
ArrayIndexOutOfBoundsException. Runtime exception thrown when accessing invalid indices.
ArrayIndexOutOfBoundsException. Runtime exception thrown when accessing invalid indices.
← Didn't Know|Knew It →
What is the result of 'array.length' in a 2D array?
What is the result of 'array.length' in a 2D array?
Tap to reveal answer
Number of rows. Returns the count of rows in the array.
Number of rows. Returns the count of rows in the array.
← Didn't Know|Knew It →
What is the result of 'array[2].length' if array has 3 rows, unequal columns?
What is the result of 'array[2].length' if array has 3 rows, unequal columns?
Tap to reveal answer
Length of third row. Returns column count specifically for row at index 2.
Length of third row. Returns column count specifically for row at index 2.
← Didn't Know|Knew It →
What is initialized first in a nested loop for 2D array traversal?
What is initialized first in a nested loop for 2D array traversal?
Tap to reveal answer
Row index. Outer loop variable controls row position first.
Row index. Outer loop variable controls row position first.
← Didn't Know|Knew It →