public class aa { public static void main(String args[]) { System.out.println("Perfect numbers from 1 to 650"); test1(); } public static void test1() { int divisor; int number = 1; int sum = 0; for(divisor=1; divisor<number; divisor++) { if(number%divisor==0) { sum = sum + divisor; } } if(sum==number) { System.out.println(number + " is a perfect number"); } } }

**[edit]**added code tags PB

So what i need to do is find all perfect numbers between 1 and 650. A perfect number is a number whose divisors(except the number itself) equal to the original number. For example, divisors of 6 are 1,2, and 3. 1+2+3=6 so 6 is a perfect number. i figured out how to get the divisors of a number and add them together, but for some reason i cant increment to next number. If i set variable "number" in my formula for example to 6 it will print. I've tried putting an outer for and while loops and try to set outer loop counter to = number but it says variable not found. I was wondering is there a way to make a variable accessible to both outer and inner loop? Any help would be great. Thanks.

This post has been edited by **PennyBoki**: 30 September 2007 - 06:33 AM