AP CSA 2017 FRQ 1 Digits

FRQ Archive2017 FRQs › FRQ 1: Digits
2017 AP CSA • Class Writing

AP CSA 2017 FRQ 1: Digits

Complete solution, scoring rubric, and walkthrough — verified from the official College Board PDF

9 Points Medium Class Writing Classic Format (Pre-2019)
Question Type Class Writing
Key Skills Write the Digits class constructor (decompose a non-negative int into a digit ArrayList using % 10 and / 10 repeated div
Difficulty Medium
AP CSA Units Unit 1: Using Objects & Methods (class construction, ArrayList) and Unit 2: Selection & Iteration (loop with arithmetic, consecutive comparison).

What This Problem Asks

Write the Digits class constructor (decompose a non-negative int into a digit ArrayList using % 10 and / 10 repeated division) and isStrictlyIncreasing() (check each consecutive pair in the ArrayList).

Official Question & PDF

Download Full 2017 FRQ PDF →

PDF cannot display here. Open PDF directly →

Provided Code

public class Digits
{
    private ArrayList digitList;

    public Digits(int num)
    { /* to be implemented in part (a) */ }

    public boolean isStrictlyIncreasing()
    { /* to be implemented in part (b) */ }
}
Timer 22:00

Part A (5 Points)

Write the Digits constructor. Initialize digitList and fill it with the digits of num in the same order they appear in the number. For num = 15704, digitList should contain [1, 5, 7, 0, 4].

Drag corner to expand ▽

 

Scoring Rubric

+1 Creates a new ArrayList
+1 Extracts digits using % 10 in a loop (or equivalent)
+1 Removes digits using / 10 (or equivalent)
+1 Handles num = 0 correctly (list contains [0])
+1 Digits appear in correct order (most significant first)

Solution

public Digits(int num)
{
    digitList = new ArrayList();

    if (num == 0)
    {
        digitList.add(0);
        return;
    }

    while (num > 0)
    {
        digitList.add(0, num % 10);  // prepend digit
        num /= 10;
    }
}
% 10 gives the last digit; / 10 removes it. Adding at index 0 (prepend) reverses the extraction order so digits end up left-to-right. The num == 0 edge case must be handled separately since the loop never executes for 0.

Part B (4 Points)

Write isStrictlyIncreasing(). Return true if each element in digitList is strictly greater than the element before it.

Drag corner to expand ▽

 

Scoring Rubric

+1 Accesses consecutive pairs (index i and i+1)
+1 Loop bound is correct (0 to size-2)
+1 Comparison is strictly greater than (not >=)
+1 Returns correct boolean (algorithm)

Solution

public boolean isStrictlyIncreasing()
{
    for (int i = 0; i < digitList.size() - 1; i++)
    {
        if (digitList.get(i) >= digitList.get(i + 1))
        {
            return false;
        }
    }
    return true;
}
Loop from 0 to size()-2 (inclusive) to compare each element with the next. Return false immediately on any violation. Return true only after the entire list passes.

Common Mistakes to Avoid

Appending digits without reversing

Wrong

digitList.add(num % 10);  // appends, gives digits in reverse order

Correct

digitList.add(0, num % 10);  // prepends, maintains correct order

add(digit) appends to the end, producing digits in reverse order. Use add(0, digit) to prepend, or reverse the list afterward.

Loop bound off-by-one in isStrictlyIncreasing

Wrong

for (int i = 0; i < digitList.size(); i++) // throws IndexOutOfBoundsException

Correct

for (int i = 0; i < digitList.size() - 1; i++) // correct

Accessing i+1 inside the loop requires the bound to be size()-1, not size(). Going to size() causes an IndexOutOfBoundsException on the last iteration.

Using >= instead of > in comparison

Wrong

if (digitList.get(i) > digitList.get(i+1)) // wrong: equal values pass

Correct

if (digitList.get(i) >= digitList.get(i+1)) // correct: equal fails

The list must be STRICTLY increasing — equal consecutive elements are not allowed. The condition to return false is get(i) >= get(i+1).

Exam Tips

Handle the num = 0 edge case first — the loop condition num > 0 never executes for 0, leaving digitList empty.
Both methods can call digitList.size() and digitList.get(). No need to convert to an array.
For the constructor, you can also build the list in reverse then call Collections.reverse() — both approaches earn full credit.

Frequently Asked Questions

What does 2017 AP CSA FRQ 1 Digits ask?

It asks students to write the Digits class constructor, which decomposes a non-negative integer into its individual digits stored in an ArrayList in left-to-right order, and isStrictlyIncreasing(), which returns true if the digits are in strictly ascending order.

What is the key trick in the Digits constructor?

Using % 10 to extract the last digit and / 10 to remove it, repeated until the number is 0. Since this extracts digits right-to-left, each digit must be prepended (added at index 0) rather than appended, so the final list reads left-to-right.

What happens if num is 0 in the Digits constructor?

The while loop condition num > 0 is immediately false, so the loop body never executes and digitList remains empty. The num = 0 case must be handled separately — typically by checking if num == 0 first and adding a single 0 to the list.

See All 2017 AP CSA FRQs

View the complete 2017 exam hub with solutions, difficulty analysis, and scoring for all four questions.

View 2017 FRQ Hub →

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]