2007 AP CSA FRQ 1: SelfDivisor
Topic: Number Theory & Digit Manipulation
Skills Tested: While loops, modular arithmetic, digit extraction, array construction
Curriculum Alignment: Unit 2 (Selection/Iteration) (2025-2026 AP CSA)
Points: 9 | Time Estimate: ~22 minutes
Part (a)
Write the isSelfDivisor method that returns true if every digit of a number divides the number evenly.
Solution
public static boolean isSelfDivisor(int number)
{
int numRemaining = number;
while (numRemaining > 0)
{
int digit = numRemaining % 10;
if (digit == 0 || number % digit != 0)
return false;
numRemaining /= 10;
}
return true;
}
Part (b)
Write the firstNumSelfDivisors method that returns an array of the first n self-divisors starting from a given value.
Solution
public static int[] firstNumSelfDivisors(int start, int num)
{
int[] selfDivisors = new int[num];
int count = 0;
int current = start;
while (count < num)
{
if (isSelfDivisor(current))
{
selfDivisors[count] = current;
count++;
}
current++;
}
return selfDivisors;
}
Key Concepts
Common Mistakes to Avoid
Official College Board Resources
About the Author: Tanner Crow is a certified AP Computer Science teacher with 11+ years of experience.
Last updated: January 2026