-
Notifications
You must be signed in to change notification settings - Fork 0
/
perfect.java
28 lines (27 loc) · 881 Bytes
/
perfect.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.io.*;
public class perfect
{
/*Perfect
*Perfect number is a number which is equal to sum of its divisor. For eg,divisors of 6 are 1,2 and 3. The
* sum of these divisors is 6. So 6 is called as perfect number
*/
public static void main () throws IOException
{
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
System.out.println("Enter the String: ");
String in = br.readLine();
int input = Integer.parseInt(in);
int sum = 0;
for(int pro = 1; pro < input ; pro++){
if(input%pro == 0){
sum += pro;
}
}
if (sum == input){
System.out.println("Perfect Number.");
}
else {
System.out.println ("Not a Perfect Number.");
}
}
}