• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar

JavaTutorOnline

1-on-1 Online Java Training by a Senior Software Engineer

  • Home
  • AP CSA
    • FRQ Practice
      • Arrays
      • ArrayList
      • Strings
      • 2D Arrays
    • MCQ Practice
      • Booleans
      • Iteration
      • Arrays
      • View all Units
  • Courses
  • Tutorials
    • Java
    • Servlets
    • Struts
    • Spring
    • Webservice
  • FAQ
  • Testimonials
  • Blog
  • CONTACT US

AP CSA Array FRQ Practice: 15 Problems & Java Solutions

AP Computer Science A • Unit 6 Array FRQs

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.

⚡ 15 FRQ Practice Problems • 🎯 Easy to Hard Progression • 💡 AP CSA Java Quick Reference 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 ArrayIndexOutOfBoundsException during complex loops.
  • Understanding when to use standard for loops versus enhanced for-each loops.
  • 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

Concept / SyntaxWhat it does
arr.lengthReturns the size of the array. (Note: No parentheses! It is a public final field, not a method.)
arr[i]Accesses or modifies the element at index i. Valid indices are 0 through arr.length - 1.
new int[5]Instantiates a new integer array of size 5. Elements auto-initialize to 0 (or null for objects). Array sizes cannot be changed once created.
for (int i = 0; i < arr.length; i++)Standard for-loop. Use this when you need the index i, or when you need to modify elements in the array.
for (int num : arr)Enhanced for-each loop. Use this for clean, readable traversals when you only need to read values and do not need the index.
AP Computer Science A Array FRQ Practice showing Java array indexing, traversal, and common FRQ tasks
AP Computer Science A Array FRQ Practice: Java array indexing, traversal, and common FRQ patterns.

FRQ 1 — Sum of Array

Easy
Problem:

Write a method calculateSum(int[] arr) that returns the sum of all elements in the array. Assume the array is not null.

Example:

[2, 4, 6, 8] → 20

Approach:
  • 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.
Java Solution
public int calculateSum(int[] arr) {
    int sum = 0;
    for (int num : arr) {
        sum += num;
    }
    return sum;
}
Common Mistakes:
  • Trying to use arr.length() with parentheses, causing a compilation error.
  • Using a standard for loop but incorrectly looping to i <= arr.length, causing an bounds exception.

FRQ 2 — Find Maximum

Easy
Problem:

Write a method findMax(int[] arr) that returns the maximum value in the array. Assume the array has a length of at least 1.

Example:

[-5, -1, -10, -2] → -1

Approach:
  • Initialize a max variable to the very first element of the array.
  • Traverse the rest of the array, updating max whenever a strictly larger value is encountered.
Java Solution
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;
}
Common Mistakes:
  • Initializing max = 0. If the array only contains negative numbers, 0 will incorrectly be returned. Always initialize with arr[0].

FRQ 3 — Count Even Numbers

Easy
Problem:

Write a method countEvens(int[] arr) that returns the total count of even numbers in the array.

Example:

[1, 2, 3, 4, 5, 8] → 3

Approach:
  • Use an enhanced for-loop to read elements.
  • Use the modulo operator (%) to determine if a number is evenly divisible by 2.
Java Solution
public int countEvens(int[] arr) {
    int count = 0;
    for (int num : arr) {
        if (num % 2 == 0) {
            count++;
        }
    }
    return count;
}
Common Mistakes:
  • Using division (num / 2 == 0) instead of modulo (%).
  • Forgetting that 0 and negative even integers correctly satisfy num % 2 == 0.

FRQ 4 — Swap First and Last

Easy
Problem:

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.

Example:

[10, 20, 30] → Modifies array to [30, 20, 10]

Approach:
  • 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.
Java Solution
public void swapEnds(int[] arr) {
    if (arr.length >= 2) {
        int temp = arr[0];
        arr[0] = arr[arr.length - 1];
        arr[arr.length - 1] = temp;
    }
}
Common Mistakes:
  • Forgetting to declare the temp variable, which causes the first element to be permanently lost when overwritten.
  • Using arr.length as the last index instead of arr.length - 1.

FRQ 5 — Reverse in Place

Medium
Problem:

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.

Example:

[1, 2, 3, 4] → Modifies array to [4, 3, 2, 1]

Approach:
  • Loop exactly halfway through the array (arr.length / 2).
  • Swap the element at index i with the element at index arr.length - 1 - i.
Java Solution
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;
    }
}
Common Mistakes:
  • 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

Medium
Problem:

Write a method contains(int[] arr, int target) that returns true if the target integer exists anywhere in the array, and false otherwise.

Example:

[5, 12, 9, 3], 9 → true

Approach:
  • Traverse the array. If the target is found, immediately return true to short-circuit the loop.
  • If the loop finishes entirely without returning, return false at the very end.
Java Solution
public boolean contains(int[] arr, int target) {
    for (int num : arr) {
        if (num == target) {
            return true;
        }
    }
    return false;
}
Common Mistakes:
  • 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

Medium
Problem:

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.

Example:

[“cat”, “elephant”, “dog”] → “elephant”

Approach:
  • Initialize a longest variable to arr[0].
  • Compare the length of each string to the length of the current longest string.
Java Solution
public String longestString(String[] arr) {
    String longest = arr[0];
    for (String s : arr) {
        if (s.length() > longest.length()) {
            longest = s;
        }
    }
    return longest;
}
Common Mistakes:
  • Confusing the syntax: using arr.length() (incorrect for arrays) or s.length (incorrect for Strings). Array size is a property; String size is a method.

FRQ 8 — Shift Left

Hard
Problem:

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.

Example:

[10, 20, 30, 40] → Modifies array to [20, 30, 40, 10]

Approach:
  • 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.
Java Solution
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;
    }
}
Common Mistakes:
  • 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

Hard
Problem:

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.

Example:

[10, 20, 30, 40] → Modifies array to [40, 10, 20, 30]

Approach:
  • 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.
Java Solution
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;
    }
}
Common Mistakes:
  • 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

Medium
Problem:

Write a method countPairs(int[] arr) that returns the number of times two adjacent elements are identically equal.

Example:

[1, 2, 2, 3, 4, 4] → 2

Approach:
  • Use a standard for loop to evaluate arr[i] and arr[i + 1] simultaneously.
  • Stop the loop one index early (arr.length - 1) to prevent stepping out of bounds when checking i + 1.
Java Solution
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;
}
Common Mistakes:
  • Looping to i < arr.length, which guarantees an ArrayIndexOutOfBoundsException on the very last iteration when evaluating arr[i + 1].

FRQ 11 — Are All Elements Positive?

Medium
Problem:

Write a method isStrictlyPositive(int[] arr) that returns true if every single integer in the array is strictly greater than zero.

Example:

[2, 4, 10] → true, [2, 0, 10] → false

Approach:
  • Traverse the array. The moment you find a number that is <= 0, immediately return false.
  • If the loop completes without finding any violations, return true.
Java Solution
public boolean isStrictlyPositive(int[] arr) {
    for (int num : arr) {
        if (num <= 0) {
            return false;
        }
    }
    return true;
}
Common Mistakes:
  • Returning true inside the loop upon finding the first positive number. You must verify all numbers before returning true.

FRQ 12 — Contains Duplicates

Hard
Problem:

Write a method hasDuplicates(int[] arr) that returns true if any value appears more than once in the array, and false otherwise.

Example:

[1, 2, 3, 2] → true

Approach:
  • Use a nested for loop. The outer loop selects a target element at index i.
  • The inner loop searches the remainder of the array (starting at i + 1) to see if that value appears again.
Java Solution
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;
}
Common Mistakes:
  • Starting the inner loop at 0 or i. This will cause the element to compare against itself and falsely return true every time.

FRQ 13 — Merge Alternating Arrays (Zip)

Hard
Problem:

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.).

Example:

[1, 2], [9, 8] → [1, 9, 2, 8]

Approach:
  • Create a new result array sized a.length * 2.
  • Use an independent idx variable to track the next available open slot in the result array.
Java Solution
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;
}
Common Mistakes:
  • Attempting to use the loop index i directly to place items into the result array, causing elements to overwrite each other.

FRQ 14 — Filter Evens (Resize Array)

Hard
Problem:

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.

Example:

[1, 2, 3, 4] → [2, 4]

Approach:
  • 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.
Java Solution
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;
}
Common Mistakes:
  • 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

Hard
Problem:

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.

Example:

[10, 5, 2, 20] → (10 + 5) / 2 → 7.5

Approach:
  • 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.
Java Solution
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;
}
Common Mistakes:
  • 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, never arr.length().
  • Remember that array indices start at 0 and end at arr.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

Primary Sidebar

Mr Chinmay

Chinmay Patel
Book a Demo Class

Phone & Whatsapp +919853166385
javatution@gmail.com

Recent Posts

  • Learn Java in One Day: 10-Hour 1-on-1 Crash Course | JavaTutorOnline
  • Constructor in Java: Examples, Types & Constructor Overloading
  • Important Interview Questions on Java Multithreading
  • React Spring Boot Web Services React Integration
  • Spring Boot RESTful Web Services Example
  • Top Spring MVC Interview Questions and Answers for Developers
  • Top Spring Core Interview Questions and Answers for Developers
  • Host Java Web Apps for Free on Mobile with Tomcat and Termux
  • How to Deploy Java Web Application on Aws EC2 with Elastic IP
  • Simple Jsp Servlet Jdbc User Registration using Tomcat Mysql and Eclipse

Additional Resources

  • AP Computer Science A Summer Prep
Copyright © 2026 JavaTutorOnline