AP Computer Science a Flashcards: 2d Array Traversals

Study 2d Array Traversals in AP Computer Science a with focused flashcards that help you recognize the idea, recall the key rule, and apply it in practice-style prompts.

AP Computer Science a

2d Array Traversals

0 mastered0 still learning

0% Complete

QUESTION
1/ 67

Identify the method to iterate over a 2D array using enhanced for-loops.

Tap card or press Space to flip

ANSWER

for (int[] row : array). Enhanced for-loop iterates over each row as an array.

How well did you know it?

Card 1 / 67

What this deck covers

This deck focuses on 2d Array Traversals, giving you a quick way to review the definitions, rules, and examples that matter most for AP Computer Science a.

How to use these flashcards

Work through these flashcards in short sessions. Try to answer each prompt before flipping the card, then revisit any cards you miss until the explanation feels automatic.

All flashcards

Flashcard 1: Identify the method to iterate over a 2D array using enhanced for-loops.

Answer: for (int[] row : array). Enhanced for-loop iterates over each row as an array.

Flashcard 2: Identify the method to get the number of columns in a 2D array.

Answer: array[0].length. Accesses the length of the first row to get column count.

Flashcard 3: What is the default value of elements in a newly created boolean 2D array?

Answer: false. Boolean arrays initialize all elements to false by default.

Flashcard 4: Identify the method to get the number of columns in a 2D array.

Answer: array[0].length. Accesses the length of the first row to get column count.

Flashcard 5: How do you initialize a 2D array with values 1 to 4 in Java?

Answer: int[][] array = { {1, 2}, {3, 4} };. Direct initialization with literal values 1 through 4.

Flashcard 6: What is the typical structure of an inner loop for 2D arrays?

Answer: for (int j = 0; j < array[i].length; j++). Iterates through columns in current row i.

Flashcard 7: What does 'int[][] array = new int[3][];' initialize?

Answer: 3 rows, undefined column sizes. Creates row array without specifying column dimensions.

Flashcard 8: State the keyword used to initialize a 2D array in Java.

Answer: new. Required keyword to allocate memory for array objects.

Flashcard 9: What is the result of 'array.length' in a 2D array?

Answer: Number of rows. Returns the count of rows in the array.

Flashcard 10: Which keyword is used to create a new 2D array object in Java?

Answer: new. Essential keyword for creating array objects in memory.

Flashcard 11: What is the type of elements in 'int[][] array = new int[2][3];'?

Answer: int. Declaration specifies integer as the element type.

Flashcard 12: What is the purpose of nested loops in 2D array traversal?

Answer: To iterate over all elements. Enables systematic access to every array element.

Flashcard 13: What is the typical structure of an inner loop for 2D arrays?

Answer: for (int j = 0; j < array[i].length; j++). Iterates through columns in current row i.

Flashcard 14: What is the result of 'array[2].length' if array has 3 rows, unequal columns?

Answer: Length of third row. Returns column count specifically for row at index 2.

Flashcard 15: Find and correct the error: 'int[][] arr; arr[1][2] = 3;'

Answer: Correct: arr must be initialized before access. Array must be instantiated with 'new' before access.

Flashcard 16: What is the default value of elements in a newly created int 2D array?

Answer:

  1. Integer arrays initialize all elements to zero by default.

Flashcard 17: What does 'array.length * array[0].length' compute for a 2D array?

Answer: Total number of elements. Multiplies rows by columns for rectangular arrays.

Flashcard 18: What does 'array[0][array[0].length - 1]' access in a 2D array?

Answer: Last element in the first row. Uses length-1 to get the rightmost column index.

Flashcard 19: What is the purpose of nested loops in 2D array traversal?

Answer: To iterate over all elements. Enables systematic access to every array element.

Flashcard 20: What is initialized first in a nested loop for 2D array traversal?

Answer: Row index. Outer loop variable controls row position first.

Flashcard 21: Find and correct the error: 'int[][] arr; arr[1][2] = 3;'

Answer: Correct: arr must be initialized before access. Array must be instantiated with 'new' before access.

Flashcard 22: What is the term for accessing each element in a 2D array?

Answer: Traversal. The systematic process of visiting each element in order.

Flashcard 23: What is the initial value of 'array[i][j]' after 'int[][] array = new int[2][2];'?

Answer:

  1. New integer arrays initialize all elements to zero.

Flashcard 24: What is initialized first in a nested loop for 2D array traversal?

Answer: Row index. Outer loop variable controls row position first.

Flashcard 25: How do you assign a value to element at row 2, column 3 in array?

Answer: array[1][2] = value;. Arrays use zero-based indexing, so row 2 is index 1.

Flashcard 26: What is the initial value of 'array[i][j]' after 'int[][] array = new int[2][2];'?

Answer:

  1. New integer arrays initialize all elements to zero.

Flashcard 27: Which keyword is used to create a new 2D array object in Java?

Answer: new. Essential keyword for creating array objects in memory.

Flashcard 28: What exception is thrown by accessing an invalid 2D array index?

Answer: ArrayIndexOutOfBoundsException. Standard runtime exception for bounds violations.

Flashcard 29: What does 'array[0][array[0].length - 1]' access in a 2D array?

Answer: Last element in the first row. Uses length-1 to get the rightmost column index.

Flashcard 30: State the keyword used to initialize a 2D array in Java.

Answer: new. Required keyword to allocate memory for array objects.

Flashcard 31: What is the result of accessing an out-of-bounds index in a 2D array?

Answer: ArrayIndexOutOfBoundsException. Runtime exception thrown when accessing invalid indices.

Flashcard 32: Identify the method to iterate over a 2D array using enhanced for-loops.

Answer: for (int[] row : array). Enhanced for-loop iterates over each row as an array.

Flashcard 33: What is the term for accessing each element in a 2D array?

Answer: Traversal. The systematic process of visiting each element in order.

Flashcard 34: Find and correct the error: 'int[][] arr = new int[2][2]; arr[2][0] = 5;'

Answer: Correct: arr[1][0] = 5;. Index 2 is out of bounds for 2-row array.

Flashcard 35: What is the result of accessing an out-of-bounds index in a 2D array?

Answer: ArrayIndexOutOfBoundsException. Runtime exception thrown when accessing invalid indices.

Flashcard 36: Identify the syntax error: 'int[][] array = new int()[3][3];'

Answer: Correct: 'new int[3][3]'. Missing type specification between 'new' and brackets.

Flashcard 37: What is the function of 'array[0].length' in a 2D array?

Answer: Number of columns in the first row. Returns column count for the first row only.

Flashcard 38: What is the typical structure of an outer loop for 2D arrays?

Answer: for (int i = 0; i < array.length; i++). Iterates through each row using array.length.

Flashcard 39: How do you initialize a 2D array with values 1 to 4 in Java?

Answer: int[][] array = { {1, 2}, {3, 4} };. Direct initialization with literal values 1 through 4.

Flashcard 40: Which loop structure is commonly used for 2D array traversal?

Answer: Nested for-loops. Outer loop for rows, inner loop for columns.

Flashcard 41: Identify the expression to access the element at row i, column j.

Answer: array[i][j]. Uses row index i and column index j.

Flashcard 42: What does 'array.length * array[0].length' compute for a 2D array?

Answer: Total number of elements. Multiplies rows by columns for rectangular arrays.

Flashcard 43: What is the type of elements in 'int[][] array = new int[2][3];'?

Answer: int. Declaration specifies integer as the element type.

Flashcard 44: What is the typical structure of an outer loop for 2D arrays?

Answer: for (int i = 0; i < array.length; i++). Iterates through each row using array.length.

Flashcard 45: Identify the method to get the number of rows in a 2D array.

Answer: array.length. Returns the number of rows in the outer array dimension.

Flashcard 46: Identify the syntax error: 'int[][] array = new int()[3][3];'

Answer: Correct: 'new int[3][3]'. Missing type specification between 'new' and brackets.

Flashcard 47: What is the default value of elements in a newly created boolean 2D array?

Answer: false. Boolean arrays initialize all elements to false by default.

Flashcard 48: Find and correct the error: 'int[][] arr = new int[2][2]; arr[2][0] = 5;'

Answer: Correct: arr[1][0] = 5;. Index 2 is out of bounds for 2-row array.

Flashcard 49: What is the syntax to declare a 2D array in Java?

Answer: int[][] arrayName;. Standard declaration syntax using double brackets for 2D arrays.

Flashcard 50: What is the syntax to declare a 2D array in Java?

Answer: int[][] arrayName;. Standard declaration syntax using double brackets for 2D arrays.

Flashcard 51: What does 'int[][] array = new int[3][];' initialize?

Answer: 3 rows, undefined column sizes. Creates row array without specifying column dimensions.

Flashcard 52: What is the default value of elements in a newly created int 2D array?

Answer:

  1. Integer arrays initialize all elements to zero by default.

Flashcard 53: What operation is performed by 'array[i][j] += 1;' in a 2D array?

Answer: Increment element at array[i][j] by 1. Adds 1 to the current value at that position.

Flashcard 54: Identify the action: 'for (int[] row : array) { for (int elem : row) { sum += elem; } }'

Answer: Sum all elements in 2D array. Enhanced for-loops accumulate all array element values.

Flashcard 55: What is the syntax to declare a 2D array with specific values?

Answer: int[][] array = { {1, 2}, {3, 4} };. Initialization syntax using nested braces for values.

Flashcard 56: Identify the action: 'for (int[] row : array) { for (int elem : row) { sum += elem; } }'

Answer: Sum all elements in 2D array. Enhanced for-loops accumulate all array element values.

Flashcard 57: What operation is performed by 'array[i][j] += 1;' in a 2D array?

Answer: Increment element at array[i][j] by 1. Adds 1 to the current value at that position.

Flashcard 58: What is the syntax to declare a 2D array with specific values?

Answer: int[][] array = { {1, 2}, {3, 4} };. Initialization syntax using nested braces for values.

Flashcard 59: What is the result of 'array.length' in a 2D array?

Answer: Number of rows. Returns the count of rows in the array.

Flashcard 60: What is the function of 'array[0].length' in a 2D array?

Answer: Number of columns in the first row. Returns column count for the first row only.

Flashcard 61: Identify the expression to access the element at row i, column j.

Answer: array[i][j]. Uses row index i and column index j.

Flashcard 62: How do you assign a value to element at row 2, column 3 in array?

Answer: array[1][2] = value;. Arrays use zero-based indexing, so row 2 is index 1.

Flashcard 63: What is the result of 'array[2].length' if array has 3 rows, unequal columns?

Answer: Length of third row. Returns column count specifically for row at index 2.

Flashcard 64: Which loop structure is commonly used for 2D array traversal?

Answer: Nested for-loops. Outer loop for rows, inner loop for columns.

Flashcard 65: Identify the error: 'int[][] array = { {1, 2}, {3, 4, 5} };'

Answer: Array is jagged, not rectangular. Rows have different lengths, creating irregular structure.

Flashcard 66: Identify the error: 'int[][] array = { {1, 2}, {3, 4, 5} };'

Answer: Array is jagged, not rectangular. Rows have different lengths, creating irregular structure.

Flashcard 67: What exception is thrown by accessing an invalid 2D array index?

Answer: ArrayIndexOutOfBoundsException. Standard runtime exception for bounds violations.