AP CSA 2017 FRQ 1 Digits
AP CSA 2017 FRQ 1: Digits
Complete solution, scoring rubric, and walkthrough — verified from the official College Board PDF
| 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
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) */ }
}
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].
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;
}
}
Part B (4 Points)
Write isStrictlyIncreasing(). Return true if each element in digitList is strictly greater than the element before it.
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;
}
Common Mistakes to Avoid
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.
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.
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
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.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
Prefer email? Reach me directly at [email protected]