Array Basics in AP Computer Science A
Which loop structure would you use to iterate over every element in an array sequentially starting with the first element?
do-while loop
while loop
infinite loop
for loop
If an array of integers is sorted in ascending order, which algorithm would be most efficient for searching for a specific value?
Bubble sort
Selection sort
Binary search
Linear search
To access the first element in an array named 'data' we would use which index?
data[first]
data[start]
data[0]
data[1]
What is returned by the following code if [3, 1, 10, 8] is passed in as the argument?
public static int maximum(int[] array) { int maxValue = array[0]; for (int number: array) { if (number < maxValue) { maxValue = number; } } return maxValue; }
3
0
10
1
What will be the result of comparing two array variables using the '==' operator?
It always returns false.
It adds the elements of both arrays together.
It compares each element of the arrays.
It checks if both variables reference the same array.
What is returned by the following code if we pass in the array [65, 78, 29, 71]?
public static int codeBlock(int[] array) { int a = 0; int c = 0; for (int i = 0; i < array.length - 1; i++) { int b = 1; for (int j = i + 1; j < array.length; j++) { if (array[j] == array[i]) { b++; } ...
71
78
29
65
In Java, what does the length field of an array represent?
The maximum value stored in the array.
The number of elements in the array.
The memory size of the array.
The index of the last element in the array.

How are we doing?
Give us your feedback and let us know how we can improve
Which of the following code blocks correctly increases every element of the integer array 'array' by a hundred?
for (int i = 0; i < array.length; i++) { array[i] = array[i] * 100; }
for (int i = 0; i < array.length; i++) { array[i] = 100; }
for (int i = 0; i < array.length; i++) { array[i] = array[i] + 100; }
for (int i = 0; i < array.length; i++) { array[i] = array[i] + 100; }
What happens when an array index is out of bounds and the program does not have proper exception handling in place?
A default value is assigned to the array element at the invalid index.
The invalid index is ignored, and the program continues to run.
The program terminates with an ArrayIndexOutOfBoundsException.
The program automatically creates a larger array to accommodate the out-of-bounds index.
What does the following code do?
public static int[] codeBlock(ArrayList
Puts all elements of an ArrayList into an array in the original order
Puts all elements of an array into an ArrayList in reverse order
Puts all elements of an array into an ArrayList in the original order
Puts all elements of an ArrayList into an array in reverse order