# Program to check Perfect Number in Java | AskTheCode

Java program to check Perfect Number using *isPerfectNumber* method | Java Programming Solution

**Problem:**

An integer is said to be Perfect Number if the sum of its factors including 1 (but not the number itself ) is equal to the number itself.

For example, 6 is a perfect number because 6 = 1 + 2 + 3.

Write a method * isPerfectNumber* using the following signature that determines if parameter number is perfect number. Use this method in a main method that determine and prints all the perfect numbers between 1 and 1000.

public boolean isPerfectNumber (int number)

### Output:

6

28

496

**Code:**

```
import java.lang.*;
class PerfectNumber{
public static void main (String[] args){
PerfectNumber pn = new PerfectNumber();
for (int i = 1; i <= 1000; i++) {
boolean result = pn.isPerfectNumber(i);
if (result == true)
System.out.println(i);
}
}
public boolean isPerfectNumber(int number){
int sum = 0;
for (int i = 1; i < number; i++) {
if (number % i == 0)
sum = sum + i;
}
if (sum == number)
return true;
return false;
}
}
```