Java program to find the perfect number.

A perfect number is a positive integer which is equal to the sum of its proper positive divisors. Proper positive divisors are positive integers that fully divide the perfect number without leaving a remainder. 

package testjava.controlflow;

public class PerfectNumber 
{
	public void isPerfectNumber(int number)
	{   
		int sum = 0;
		
		System.out.print("Proper positive Divisor of "+number+" are:");
		for(int i = 1; i<number; i++)
		{
			if(number % i == 0)
			{
				System.out.print(i + " ");
				sum += i;
			}
		}
		System.out.println();
		
		if(sum == number)
			System.out.println(number +" is perfect number.");
		else
			System.out.println(number +" is not a perfect number");
	}
	
	public static void main(String args[])
	{
		PerfectNumber pn = new PerfectNumber();
		pn.isPerfectNumber(6);
		pn.isPerfectNumber(12);
		pn.isPerfectNumber(14);
		pn.isPerfectNumber(28);
	}
}

OUTPUT

Proper positive Divisor of 6 are:1 2 3 
6 is perfect number.
Proper positive Divisor of 12 are:1 2 3 4 6 
12 is not a perfect number
Proper positive Divisor of 14 are:1 2 7 
14 is not a perfect number
Proper positive Divisor of 28 are:1 2 4 7 14 
28 is perfect number.