Array Creation and Access - AP Computer Science A
Card 1 of 30
What does 'arr[0][1]' refer to in a 2D array 'arr'?
What does 'arr[0][1]' refer to in a 2D array 'arr'?
Tap to reveal answer
Element in first row, second column. First index is row, second is column.
Element in first row, second column. First index is row, second is column.
← Didn't Know|Knew It →
What does 'arr[0].length' return for char[][] arr = new char[5][6]?
What does 'arr[0].length' return for char[][] arr = new char[5][6]?
Tap to reveal answer
- Returns number of columns in first row.
- Returns number of columns in first row.
← Didn't Know|Knew It →
What is the default value of an uninitialized boolean array element?
What is the default value of an uninitialized boolean array element?
Tap to reveal answer
false. Boolean arrays initialize to false by default.
false. Boolean arrays initialize to false by default.
← Didn't Know|Knew It →
What will 'arr.length' return for an empty array 'arr'?
What will 'arr.length' return for an empty array 'arr'?
Tap to reveal answer
- Empty arrays have zero length.
- Empty arrays have zero length.
← Didn't Know|Knew It →
What is the syntax to declare an array of doubles named 'prices'?
What is the syntax to declare an array of doubles named 'prices'?
Tap to reveal answer
double[] prices;. Declaration without instantiation using semicolon.
double[] prices;. Declaration without instantiation using semicolon.
← Didn't Know|Knew It →
How do you declare a 3x3 2D array of integers?
How do you declare a 3x3 2D array of integers?
Tap to reveal answer
int[][] arr = new int[3][3];. Creates rectangular array with specified dimensions.
int[][] arr = new int[3][3];. Creates rectangular array with specified dimensions.
← Didn't Know|Knew It →
How do you access the last element of an array 'arr'?
How do you access the last element of an array 'arr'?
Tap to reveal answer
arr[arr.length - 1]. Uses array length minus one for last index.
arr[arr.length - 1]. Uses array length minus one for last index.
← Didn't Know|Knew It →
What is the result of 'Arrays.toString(arr)' for int[] arr = {1, 2, 3}?
What is the result of 'Arrays.toString(arr)' for int[] arr = {1, 2, 3}?
Tap to reveal answer
[1, 2, 3]. Utility method converts array to string representation.
[1, 2, 3]. Utility method converts array to string representation.
← Didn't Know|Knew It →
What does 'arr[1][1]' access in int[][] arr = {{1, 2}, {3, 4}}?
What does 'arr[1][1]' access in int[][] arr = {{1, 2}, {3, 4}}?
Tap to reveal answer
- Accesses row 1, column 1 (second row, second column).
- Accesses row 1, column 1 (second row, second column).
← Didn't Know|Knew It →
What does 'arr[0].length' return for char[][] arr = new char[5][6]?
What does 'arr[0].length' return for char[][] arr = new char[5][6]?
Tap to reveal answer
- Returns number of columns in first row.
- Returns number of columns in first row.
← Didn't Know|Knew It →
How do you create a new array of 5 float elements?
How do you create a new array of 5 float elements?
Tap to reveal answer
float[] arr = new float[5];. Standard syntax for float array creation.
float[] arr = new float[5];. Standard syntax for float array creation.
← Didn't Know|Knew It →
How is a two-dimensional array initialized with values in Java?
How is a two-dimensional array initialized with values in Java?
Tap to reveal answer
int[][] arr = {{1, 2}, {3, 4}};. Nested braces initialize rows and columns.
int[][] arr = {{1, 2}, {3, 4}};. Nested braces initialize rows and columns.
← Didn't Know|Knew It →
What is the syntax to declare an integer array named 'arr' with 10 elements?
What is the syntax to declare an integer array named 'arr' with 10 elements?
Tap to reveal answer
int[] arr = new int[10];. Standard array declaration: type[] name = new type[size];
int[] arr = new int[10];. Standard array declaration: type[] name = new type[size];
← Didn't Know|Knew It →
Which keyword is used to create a new array in Java?
Which keyword is used to create a new array in Java?
Tap to reveal answer
new. Instantiates array objects in memory.
new. Instantiates array objects in memory.
← Didn't Know|Knew It →
How do you access the third element of an array named 'arr'?
How do you access the third element of an array named 'arr'?
Tap to reveal answer
arr[2]. Arrays use 0-based indexing, so index 2 is the third element.
arr[2]. Arrays use 0-based indexing, so index 2 is the third element.
← Didn't Know|Knew It →
What will 'arr.length' return for an array 'arr' of 5 elements?
What will 'arr.length' return for an array 'arr' of 5 elements?
Tap to reveal answer
- Property returns total number of elements in array.
- Property returns total number of elements in array.
← Didn't Know|Knew It →
Identify the error: int[] arr = new int[-5];
Identify the error: int[] arr = new int[-5];
Tap to reveal answer
Array size cannot be negative. Array size must be non-negative integer.
Array size cannot be negative. Array size must be non-negative integer.
← Didn't Know|Knew It →
What is the default value of an uninitialized int array element?
What is the default value of an uninitialized int array element?
Tap to reveal answer
- Numeric primitive arrays initialize to zero.
- Numeric primitive arrays initialize to zero.
← Didn't Know|Knew It →
How do you initialize an array of strings named 'colors' with 'red', 'green', 'blue'?
How do you initialize an array of strings named 'colors' with 'red', 'green', 'blue'?
Tap to reveal answer
String[] colors = {"red", "green", "blue"};. Array literal syntax using curly braces.
String[] colors = {"red", "green", "blue"};. Array literal syntax using curly braces.
← Didn't Know|Knew It →
What exception is thrown for accessing an invalid array index?
What exception is thrown for accessing an invalid array index?
Tap to reveal answer
ArrayIndexOutOfBoundsException. Runtime exception for invalid array indices.
ArrayIndexOutOfBoundsException. Runtime exception for invalid array indices.
← Didn't Know|Knew It →
How do you declare a two-dimensional array of integers?
How do you declare a two-dimensional array of integers?
Tap to reveal answer
int[][] arr;. Double brackets indicate two dimensions.
int[][] arr;. Double brackets indicate two dimensions.
← Didn't Know|Knew It →
Find the correct syntax to fill the array 'arr' with zeros.
Find the correct syntax to fill the array 'arr' with zeros.
Tap to reveal answer
Arrays.fill(arr, 0);. Utility method fills entire array with specified value.
Arrays.fill(arr, 0);. Utility method fills entire array with specified value.
← Didn't Know|Knew It →
Identify the error: double[] arr = {1, 2, '3'};
Identify the error: double[] arr = {1, 2, '3'};
Tap to reveal answer
Incompatible types: char cannot be converted to double. Type mismatch: char literal incompatible with double array.
Incompatible types: char cannot be converted to double. Type mismatch: char literal incompatible with double array.
← Didn't Know|Knew It →
What is the syntax to declare a char array named 'letters' with size 5?
What is the syntax to declare a char array named 'letters' with size 5?
Tap to reveal answer
char[] letters = new char[5];. Standard syntax for character array declaration.
char[] letters = new char[5];. Standard syntax for character array declaration.
← Didn't Know|Knew It →
How do you assign a value 42 to the fifth element of an array 'arr'?
How do you assign a value 42 to the fifth element of an array 'arr'?
Tap to reveal answer
arr[4] = 42;. Fifth element has index 4 in zero-based indexing.
arr[4] = 42;. Fifth element has index 4 in zero-based indexing.
← Didn't Know|Knew It →
What is 'arr[1]' if int[] arr = {10, 20, 30}?
What is 'arr[1]' if int[] arr = {10, 20, 30}?
Tap to reveal answer
- Index 1 accesses the second element.
- Index 1 accesses the second element.
← Didn't Know|Knew It →
What will the expression 'arr[2].length' return for int[][] arr = new int[3][4]?
What will the expression 'arr[2].length' return for int[][] arr = new int[3][4]?
Tap to reveal answer
- Returns column count of row at index 2.
- Returns column count of row at index 2.
← Didn't Know|Knew It →
Which expression evaluates to the length of the first row in a 2D array 'arr'?
Which expression evaluates to the length of the first row in a 2D array 'arr'?
Tap to reveal answer
arr[0].length. Accesses length property of first row.
arr[0].length. Accesses length property of first row.
← Didn't Know|Knew It →
What is the syntax to declare an empty array of integers?
What is the syntax to declare an empty array of integers?
Tap to reveal answer
int[] arr = {};. Empty braces create zero-length array.
int[] arr = {};. Empty braces create zero-length array.
← Didn't Know|Knew It →
What is the syntax to declare a long array with 100 elements?
What is the syntax to declare a long array with 100 elements?
Tap to reveal answer
long[] arr = new long[100];. Standard syntax for long array with specified size.
long[] arr = new long[100];. Standard syntax for long array with specified size.
← Didn't Know|Knew It →