/**
 * Computes the first four perfect numbers. A perfect number is an integer that is equal 
 * to the sum of its positive divisors. 
 * 
 * @author Drue Coles
 */
public class PerfectNumbers {

    public static void main(String[] args) {

        System.out.println("PERFECT NUMBERS");

        int solutionsFound = 0;    
        final int maxNumSolutions = 4;     
        int numToTest = 1; 
        
        while (solutionsFound < maxNumSolutions) {

            // Calculate the sum of the positive divisors of numToTest.
            int sumOfDivisors = 0;
            for (int k = 1; k < numToTest; k++) {
                if (numToTest % k == 0) {
                    sumOfDivisors += k;
                }
            }

            // Check if numToTest is perfect. 
            if (sumOfDivisors == numToTest) {
                solutionsFound++;
                System.out.println(solutionsFound + ". " + numToTest);
            }

            numToTest++;
        }
    }
}