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
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
To access the first element in an array named 'data' we would use which index?
data[first]
data[start]
data[0]
data[1]
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.
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
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; }

How are we doing?
Give us your feedback and let us know how we can improve
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 does the following code do?
public static int[] codeBlock(int[] array) { int firstItem = array[0] for (int i = 0; i < array.length - 1; i++) { array[i] = array[i+1]; } array[array.length - 1] = firstItem; return array; }
Shifts elements in an array to the right by one
Shifts elements in an array to the left by two
Shifts elements in an array to the left by one
Reverses the order of elements in an array
Which element does arr[0]
refer to in a non-empty array arr
in Java?
The second element
The middle element
The first element
The last element