Arrays – FRQ Practice (AP Computer Science A)
1D Arrays form the foundation of Java data structures and are featured on almost every AP Computer Science A exam. Master these 15 original AP CSA-style Array practice problems featuring clean Java solutions, common boundary pitfalls to avoid, and step-by-step traversal logic.
Students must know how to traverse arrays, swap elements, locate maximum/minimum values, filter elements into new arrays, and shift elements safely. Use this page as your ultimate practice hub to master 1D Array algorithms for the AP exam.
Why Practice Array FRQs?
- Preventing
ArrayIndexOutOfBoundsExceptionduring complex loops. - Understanding when to use standard
forloops versus enhancedfor-eachloops. - Mastering in-place modification (swapping and shifting elements).
- Learning how to dynamically size and return new arrays based on filtering logic.
- Accumulating data (sums, averages, and counts) via safe traversal.
AP CSA Array Concepts You Should Know

FRQ 1 — Sum of Array
Write a method calculateSum(int[] arr) that returns the sum of all elements in the array. Assume the array is not null.
[2, 4, 6, 8] → 20
- Because we only need to read all the values (no index tracking required), an enhanced for-loop is the cleanest approach.
- Accumulate the values into a running total variable.
public int calculateSum(int[] arr) {
int sum = 0;
for (int num : arr) {
sum += num;
}
return sum;
}- Trying to use
arr.length()with parentheses, causing a compilation error. - Using a standard
forloop but incorrectly looping toi <= arr.length, causing an bounds exception.
FRQ 2 — Find Maximum
Write a method findMax(int[] arr) that returns the maximum value in the array. Assume the array has a length of at least 1.
[-5, -1, -10, -2] → -1
- Initialize a
maxvariable to the very first element of the array. - Traverse the rest of the array, updating
maxwhenever a strictly larger value is encountered.
public int findMax(int[] arr) {
int max = arr[0];
for (int i = 1; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
return max;
}- Initializing
max = 0. If the array only contains negative numbers,0will incorrectly be returned. Always initialize witharr[0].
FRQ 3 — Count Even Numbers
Write a method countEvens(int[] arr) that returns the total count of even numbers in the array.
[1, 2, 3, 4, 5, 8] → 3
- Use an enhanced for-loop to read elements.
- Use the modulo operator (
%) to determine if a number is evenly divisible by 2.
public int countEvens(int[] arr) {
int count = 0;
for (int num : arr) {
if (num % 2 == 0) {
count++;
}
}
return count;
}- Using division (
num / 2 == 0) instead of modulo (%). - Forgetting that
0and negative even integers correctly satisfynum % 2 == 0.
FRQ 4 — Swap First and Last
Write a method swapEnds(int[] arr) that modifies the array by swapping its first and last elements. Assume the array might be empty or contain only 1 element, in which case it should remain unchanged.
[10, 20, 30] → Modifies array to [30, 20, 10]
- Verify the array length is at least 2 to prevent an
ArrayIndexOutOfBoundsException. - Use a temporary variable (
temp) to hold the first value before overwriting it.
public void swapEnds(int[] arr) {
if (arr.length >= 2) {
int temp = arr[0];
arr[0] = arr[arr.length - 1];
arr[arr.length - 1] = temp;
}
}- Forgetting to declare the
tempvariable, which causes the first element to be permanently lost when overwritten. - Using
arr.lengthas the last index instead ofarr.length - 1.
FRQ 5 — Reverse in Place
Write a method reverseInPlace(int[] arr) that modifies the existing array to completely reverse the order of its elements. Do not create a new array.
[1, 2, 3, 4] → Modifies array to [4, 3, 2, 1]
- Loop exactly halfway through the array (
arr.length / 2). - Swap the element at index
iwith the element at indexarr.length - 1 - i.
public void reverseInPlace(int[] arr) {
for (int i = 0; i < arr.length / 2; i++) {
int temp = arr[i];
arr[i] = arr[arr.length - 1 - i];
arr[arr.length - 1 - i] = temp;
}
}- Looping completely through to
arr.length. This reverses the array in the first half, and then swaps it all right back to its original state in the second half.
FRQ 6 — Check for Target
Write a method contains(int[] arr, int target) that returns true if the target integer exists anywhere in the array, and false otherwise.
[5, 12, 9, 3], 9 → true
- Traverse the array. If the target is found, immediately return
trueto short-circuit the loop. - If the loop finishes entirely without returning, return
falseat the very end.
public boolean contains(int[] arr, int target) {
for (int num : arr) {
if (num == target) {
return true;
}
}
return false;
}- Adding an
else { return false; }block inside the loop. This causes the method to only check the very first element and immediately exit, failing on all subsequent elements.
FRQ 7 — Find Longest String
Write a method longestString(String[] arr) that returns the string with the most characters. Assume the array has a length of at least 1, and no strings are null. If there is a tie, return the first longest string.
[“cat”, “elephant”, “dog”] → “elephant”
- Initialize a
longestvariable toarr[0]. - Compare the length of each string to the length of the current
longeststring.
public String longestString(String[] arr) {
String longest = arr[0];
for (String s : arr) {
if (s.length() > longest.length()) {
longest = s;
}
}
return longest;
}- Confusing the syntax: using
arr.length()(incorrect for arrays) ors.length(incorrect for Strings). Array size is a property; String size is a method.
FRQ 8 — Shift Left
Write a method shiftLeft(int[] arr) that modifies the array by shifting all elements one index to the left. The element at index 0 should wrap around to the last index.
[10, 20, 30, 40] → Modifies array to [20, 30, 40, 10]
- Save the very first element into a temporary variable.
- Loop from index 0 up to the second-to-last index, pulling elements from the right (
arr[i] = arr[i+1]). - Place the temporary variable into the very last index.
public void shiftLeft(int[] arr) {
if (arr.length > 0) {
int first = arr[0];
for (int i = 0; i < arr.length - 1; i++) {
arr[i] = arr[i + 1];
}
arr[arr.length - 1] = first;
}
}- Looping backwards. If you pull elements the wrong direction in a shift-left, you overwrite data before it can be copied.
FRQ 9 — Shift Right
Write a method shiftRight(int[] arr) that modifies the array by shifting all elements one index to the right. The last element should wrap around to index 0.
[10, 20, 30, 40] → Modifies array to [40, 10, 20, 30]
- Save the very last element into a temporary variable.
- Loop backwards from the end of the array down to index 1, pulling elements from the left (
arr[i] = arr[i-1]). - Place the temporary variable into index 0.
public void shiftRight(int[] arr) {
if (arr.length > 0) {
int last = arr[arr.length - 1];
for (int i = arr.length - 1; i > 0; i--) {
arr[i] = arr[i - 1];
}
arr[0] = last;
}
}- Looping forwards (left-to-right). This incorrectly copies the first element across the entire array, turning
[10, 20, 30]into[30, 10, 10].
FRQ 10 — Count Consecutive Pairs
Write a method countPairs(int[] arr) that returns the number of times two adjacent elements are identically equal.
[1, 2, 2, 3, 4, 4] → 2
- Use a standard
forloop to evaluatearr[i]andarr[i + 1]simultaneously. - Stop the loop one index early (
arr.length - 1) to prevent stepping out of bounds when checkingi + 1.
public int countPairs(int[] arr) {
int count = 0;
for (int i = 0; i < arr.length - 1; i++) {
if (arr[i] == arr[i + 1]) {
count++;
}
}
return count;
}- Looping to
i < arr.length, which guarantees anArrayIndexOutOfBoundsExceptionon the very last iteration when evaluatingarr[i + 1].
FRQ 11 — Are All Elements Positive?
Write a method isStrictlyPositive(int[] arr) that returns true if every single integer in the array is strictly greater than zero.
[2, 4, 10] → true, [2, 0, 10] → false
- Traverse the array. The moment you find a number that is
<= 0, immediately returnfalse. - If the loop completes without finding any violations, return
true.
public boolean isStrictlyPositive(int[] arr) {
for (int num : arr) {
if (num <= 0) {
return false;
}
}
return true;
}- Returning
trueinside the loop upon finding the first positive number. You must verify all numbers before returningtrue.
FRQ 12 — Contains Duplicates
Write a method hasDuplicates(int[] arr) that returns true if any value appears more than once in the array, and false otherwise.
[1, 2, 3, 2] → true
- Use a nested
forloop. The outer loop selects a target element at indexi. - The inner loop searches the remainder of the array (starting at
i + 1) to see if that value appears again.
public boolean hasDuplicates(int[] arr) {
for (int i = 0; i < arr.length; i++) {
for (int j = i + 1; j < arr.length; j++) {
if (arr[i] == arr[j]) {
return true;
}
}
}
return false;
}- Starting the inner loop at
0ori. This will cause the element to compare against itself and falsely returntrueevery time.
FRQ 13 — Merge Alternating Arrays (Zip)
Write a method mergeAlternating(int[] a, int[] b). Assume a and b have the exact same length. Return a new array containing all elements from both arrays alternating (a[0], b[0], a[1], b[1], etc.).
[1, 2], [9, 8] → [1, 9, 2, 8]
- Create a new
resultarray sizeda.length * 2. - Use an independent
idxvariable to track the next available open slot in theresultarray.
public int[] mergeAlternating(int[] a, int[] b) {
int[] result = new int[a.length * 2];
int idx = 0;
for (int i = 0; i < a.length; i++) {
result[idx] = a[i];
idx++;
result[idx] = b[i];
idx++;
}
return result;
}- Attempting to use the loop index
idirectly to place items into the result array, causing elements to overwrite each other.
FRQ 14 — Filter Evens (Resize Array)
Write a method filterEvens(int[] arr) that returns a new array containing only the even numbers from the original array. The new array must be exactly perfectly sized so there are no trailing empty zeros.
[1, 2, 3, 4] → [2, 4]
- Since standard Java arrays cannot change size once instantiated, you must use a two-pass approach.
- Pass 1: Count the even numbers to determine the exact size needed for the new array.
- Pass 2: Instantiate the new array and populate it with the even numbers.
public int[] filterEvens(int[] arr) {
// Pass 1: Count the evens
int count = 0;
for (int num : arr) {
if (num % 2 == 0) {
count++;
}
}
// Pass 2: Populate exactly sized array
int[] result = new int[count];
int idx = 0;
for (int num : arr) {
if (num % 2 == 0) {
result[idx] = num;
idx++;
}
}
return result;
}- Sizing the new array to
arr.length, which leaves invalid trailing zeros (e.g.,[2, 4, 0, 0]) that violate the exact sizing requirement.
FRQ 15 — Average without Extremes
Write a method centeredAverage(int[] arr) that calculates the average of all elements, excluding the maximum value and the minimum value. Assume the array length is at least 3. If there are multiple copies of the minimum or maximum, ignore only one copy of each. Use double precision for the final division.
[10, 5, 2, 20] → (10 + 5) / 2 → 7.5
- Traverse the array once. Accumulate the total sum, while simultaneously keeping track of the minimum and maximum values seen so far.
- Subtract the min and max from the sum, and divide by
arr.length - 2.
public double centeredAverage(int[] arr) {
int sum = 0;
int min = arr[0];
int max = arr[0];
for (int num : arr) {
sum += num;
if (num < min) min = num;
if (num > max) max = num;
}
int adjustedSum = sum - min - max;
int adjustedCount = arr.length - 2;
return (double) adjustedSum / adjustedCount;
}- Forgetting to cast the final calculation to a
(double), resulting in Java integer division which permanently truncates the decimal answer.
Frequently Asked Questions
What is the difference between length and length() in Java?
For arrays, length is a public final property (no parentheses). For Strings, length() is a method (requires parentheses). Using parentheses on an array will cause a compilation error on the AP exam.
When should I use an enhanced for loop vs a standard for loop?
Use an enhanced for loop (for (int num : arr)) when you only need to read the values. Use a standard for loop (for (int i = 0; i < arr.length; i++)) when you need to know the index position or if you need to assign new values into the array.
Can I change the size of an array in Java?
No. Standard 1D arrays are static in size. Once you instantiate an array (e.g., new int[5]), it will always have a size of 5. If you need a dynamically sizing structure, you must use an ArrayList.
How do I avoid ArrayIndexOutOfBoundsException?
Always verify your loop boundaries. The valid indices for an array are exactly 0 through arr.length - 1. Be especially careful when using i + 1 inside a loop, as it requires stopping the loop one step early.
Are these official College Board FRQs?
No. These are original, custom-designed AP CSA–style practice problems created for additional practice. They are not released College Board questions.
FRQ Strategy Tips for Arrays (AP CSA)
- Always check boundary conditions, especially when comparing adjacent elements or swapping ends.
- Differentiate between modifying elements in-place and returning an entirely new array.
- Double-check your syntax: use
arr.length, neverarr.length(). - Remember that array indices start at
0and end atarr.length - 1. - Write clear, logically structured solutions and verify you have returned the requested data type.
Related FRQ Pages
- Strings – FRQ Practice
- ArrayList – FRQ Practice
- 2D Arrays – FRQ Practice
- Classes & Objects – FRQ Practice
- Mixed FRQs
- Mock FRQ Sets
Need Structured Help With AP Computer Science A?
If you want guided, one-on-one support for AP Computer Science A—including FRQs, MCQs, debugging, and exam strategy—you can explore my private AP CSA online tutoring program.
Ideal for students targeting a score of 4 or 5 on the AP CSA exam.
WhatsApp: +91 9853166385
Email: javatution@gmail.com
Book a free demo: Contact Chinmay