Question 1111
Consider the following method.
public static int classify(int n) {
int sumDiv = 0;
for (int i = 1; i < n; i++) {
if (n % i == 0)
sumDiv += i;
}
if (sumDiv == n) return 0;
if (sumDiv > n) return 1;
return -1;
}
What is the return value of classify(28) ?
Main Solution
To determine the return value of classify(28), we need to find all proper divisors of 28 (i.e., all integers i where 1 ≤ i < 28 and 28 % i == 0), then sum them.
The divisors of 28 that are less than 28 are: 1, 2, 4, 7, 14.
Sum: \(1 + 2 + 4 + 7 + 14 = 28\)
So sumDiv = 28, which equals n = 28.
The condition if (sumDiv == n) is true, so the method returns 0.
The correct answer is A.
Note: 28 is a perfect number — a number equal to the sum of its proper divisors. The method essentially classifies numbers: 0 for perfect, 1 for abundant (sum > n), and -1 for deficient (sum < n).
Teacher Explanation
This question tests students' ability to trace through a loop and accumulate a sum. The key insight is recognizing that the loop iterates i from 1 up to (but not including) n, adding i to sumDiv whenever i is a divisor of n. For n = 28, the proper divisors are 1, 2, 4, 7, 14, which sum to 28 — making 28 a perfect number and causing the method to return 0.
Education Coach Advice
AP Exam Strategy: When tracing loops, carefully check the loop bounds — here i < n (strict inequality) means n itself is never tested as a divisor. List out all divisors systematically and sum them before evaluating the conditionals. For number-theory style problems, recall that perfect numbers (like 6, 28, 496) equal the sum of their proper divisors.
Traps
Common traps:
- Option B (1): Students might mistakenly include 28 itself as a divisor (since
28 % 28 == 0), giving a sum of 56 > 28, and incorrectly returning 1. However, the loop condition isi < n, soi = 28is never tested. - Option C (-1): Students might miscalculate the sum of divisors and get a value less than 28, returning -1.
- Option D (28): Students might confuse the return value with the input value.
Answer images

