Perfect number algorithm & Java program

Perfect number: A number is called as perfect number when the sum of all it's factors divided by 2 gives the same number as a result. It's very simple, look at below expression

(sum of all factors of n)/2 = n

The first positive perfect number is 6. The factors of 6 are 1, 2, 3, and 6. The sum of all the factors of 6 is 12. So, 12/2 gives 6 again. Algorithm

BEGIN DECLARE sum, i, number INITIALIZE sum with 0 and i with 1 PRINT 'Enter a number' ACCEPT number LOOP UNTIL I reaches to number IF number%i = 0 THEN sum = sum + i END IF END LOOP IF sum/2 = number THEN PRINT 'Perfect number' ELSE PRINT 'Not a perfect number' END IF END

Here is a Java program based on the above algorithm. PerfectNumber.java