# Frequently Asked Java Program 28: Java Program to Find if Given Number Is a Perfect Number

### Perfect Number:

A Perfect number is a positive integer that is equal to the sum of its proper divisors excluding the number itself.

For Example: Take Number 6. Its divisors are 1, 2 , 3 and 6. When we add all divisors except 6 ( as it is number itself) (i.e. 1+2+3= 6), it is equal to actual number. So we can say Number 6 is a perfect number.

The smallest perfect number is 6. Other perfect numbers are 28, 496, and 8,128.

Logic:

1. When we divide a number say X by other number say Y and reminder is zero, then number Y is a proper divisor. All proper divisor of a number X are between 1 and X/2. ( 1 and X/2 are included) . To find the proper divisor we need to divide the number by 1 to number/2.
2. We need to keep adding all divisors.

Java Program:

Output:

```Please enter the number to check for perfect number :
6
You entered: 6
6 is a perfect number.
=====================================================
Please enter the number to check for perfect number :
1
You entered: 1
1 is not a perfect number.
====================================================
Please enter the number to check for perfect number :
-10
You entered: -10
A perfect number must be positive and greater than zero. So kindly enter number greater than zero.
======================================================
Please enter the number to check for perfect number :
10
You entered: 10
10 is not a perfect number.
```

#HappyCoding

#### Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.