2007 AP CSA FRQ 1: SelfDivisor - Complete Solution

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.

Try It First! Attempt to solve this part before viewing the solution.

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

Use % 10 to get the last digit
Use / 10 to remove the last digit
Check for 0 digit first to avoid division by zero
Use the helper method isSelfDivisor in part (b)

Common Mistakes to Avoid

Forgetting to check for digit == 0 (causes ArithmeticException)
Using number instead of numRemaining in the loop
Off-by-one error in array indexing
Not incrementing current in the while loop

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

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]