You have reached the final challenge of Unit 6. Mastering 1D Arrays is the bridge between basic Java syntax and advanced object-oriented data structures. If you can confidently navigate arrays, you are well on your way to earning a 5 on the AP Computer Science A exam.
This Unit 6 Mock Exam contains 15 exam-level questions that mix all the concepts we have covered: array creation, memory references, standard traversals, enhanced for-loops, and shifting algorithms.
Tips for the Mock Exam:
- Trace Everything: Do not rely on mental math. Write down the array indices and update their values as you trace through the loops.
- Check the Bounds: The most common distractor on the AP exam is the
ArrayIndexOutOfBoundsException. Always verify the loop’s starting index and its termination condition. - Remember References: If two array variables point to the same array, changing one changes the other.
Treat this like the real test. Grab a piece of scratch paper, eliminate the obvious wrong answers, and begin!
Unit 6 Mock Exam
arr[0] = 3;
arr[2] = 7;
System.out.println(arr[4]);
int[] list2 = list1;
list2[1] = 99;
System.out.println(list1[1] + list2[1]);
ArrayIndexOutOfBoundsException in a standard for-loop traversing an array named data?for (int i = vals.length – 1; i >= 0; i–) {
System.out.print(vals[i] + ” “);
}
for (int n : nums) {
n = n * 2;
}
System.out.println(nums[0]);
int temp = arr[0];
for (int i = 0; i < arr.length – 1; i++) {
arr[i] = arr[i + 1];
}
arr[arr.length – 1] = temp;
int count = 0;
for (int i = 1; i < arr.length – 1; i++) {
if (arr[i] > arr[i – 1] && arr[i] > arr[i + 1]) {
count++;
}
}
System.out.println(count);
for (int i = 0; i < arr.length; i += 2) {
arr[i] = 0;
}
flags[1] = true;
boolean result = flags[0] || flags[1];
System.out.println(result);
for (int i = 0; i < arr.length / 2; i++) {
arr[i] = arr[arr.length – 1 – i];
arr[arr.length – 1 – i] = arr[i];
}
}
for (int i = 0; i < words.length; i++) {
words[i] += “!”;
}
System.out.println(words[1]);
int x = 0;
for (int num : arr) {
if (num % 2 != 0) {
x += num;
}
}
System.out.println(x);
int max = 0;
for (int i = 0; i < nums.length; i++) {
if (nums[i] > max) {
max = nums[i];
}
}
System.out.println(max);
for (int i = 1; i < arr.length; i++) {
arr[i] = arr[i] + arr[i – 1];
}
System.out.println(arr[arr.length – 1]);
Unit 6 Exam Complete!
Moving Forward: Arrays vs. ArrayLists
Congratulations on completing the Unit 6 Arrays curriculum! If you can confidently navigate through indices, avoid bounds exceptions, and utilize both standard and enhanced for-loops, you have mastered one of the most important concepts in computer science.
However, standard 1D arrays have one massive limitation: their size is fixed. If you create an array to hold 5 items, you can never add a 6th. In the real world, data constantly grows and shrinks.
To solve this problem, Java offers a dynamic data structure that can expand automatically. Prepare to level up your programming skills by moving into ArrayLists, where we explore how to build flexible, resizable lists!
Need to Review Before Testing?
Review our targeted practice modules to brush up on specific concepts:
Want to Boost Your AP CSA Score to a 5?
Get expert, 1-on-1 online instruction tailored to your exact weak spots with a senior software engineer.
Explore AP CSA 1-on-1 Tutoring →