This is a Java Program to Check if a given Number is Perfect Number. A perfect number is a positive integer that is equal to the sum of its proper positive divisors excluding the number itself.

Enter any integer as an input. Now we use modulo operation along with loops and if conditions to check given number is a perfect number or not.

Here is the source code of the Java Program to Check if a given Number is Perfect Number. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

import java.util.Scanner;

public class Perfect

`{`

public static void main(String[] args)

`{`

int n, sum = 0;

Scanner s = new Scanner(System.in);

System.out.print("Enter any integer you want to check:");

n = s.nextInt();

for(int i = 1; i < n; i++)

`{`

if(n % i == 0)

`{`

sum = sum + i;

`}`

`}`

if(sum == n)

`{`

System.out.println("Given number is Perfect");

`}`

`else`

`{`

System.out.println("Given number is not Perfect");

`}`

`}`

int divisor(int x)

`{`

return x;

`}`

`}`

Output:

$ javac Perfect.java $ java Perfect Enter any integer you want to check:6 Given number is Perfect

**Sanfoundry Global Education & Learning Series – 1000 Java Programs.**

Here’s the list of Best Reference Books in Java Programming, Data Structures and Algorithms.