Perfect Number

perfect number, a positive integer that is equal to the sum of its proper divisors. The smallest perfect number is 6, which is the sum of 1, 2, and 3. Other perfect numbers are 28, 496, and 8,128.

Program:-

package payilagam.institution;

public class Perfect {

	public static void main(String[] args) {
		int num=28;
		
        int div=1;
        int total = 0;
        while(div<num)
        {
        	if(num%div==0)
        	{
        		System.out.println(div);
        		total = total+div;
        	}
        	
        	
        	div++;
        	
        }System.out.println(total);
		if(num==total)
		{
			System.out.println("Perfect");
		}

	}

}

Output Screenshot:-

Leave a Reply

Create your own website, free on WordPress.com.Create your own website.
Start free