Part of my homework is to make a program in Java that will take all the divisors of n and add them up. (e.g. n = 10, answer = 1+2+5 = 8) The part in italics is what (I think) keeps it from looping. The answer to all numbers is one because it doesn't loop. What can the italicized line be or am I way off?
Code:
static int slow (int n){
int divisor = 1; // number to divide n by and increases by one each time until above n
int answer = 0; // number that is being returned
//loop condition
while (divisor < n) {
if((n % divisor) == 0) {
[I]return divisor[/I]; }
answer = answer + divisor;
divisor = divisor + 1;
}
return answer;
}