-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperfect.java
46 lines (44 loc) · 1.12 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.Scanner;
class Perfect
{
static boolean perfect(int num)
{
int sum = 0;
for(int i=1; i<num; i++)
{
if(num%i==0)
{
sum = sum+i;
}
}
if(sum==num)
return true;
else
return false;
}
public static void main(String[] args)
{
try
{
Scanner obj = new Scanner (System.in);
int n=0;
System.out.println("enter the value for N");
int N = obj.nextInt();
if(N<=0)
System.out.println("enter the N value correctly");
if(N==3)
n=1000;
if(N==5)
n=100000000;
for(int i=1; i<=n; i++)
{
if(perfect(i))
System.out.println(i);
}
}
catch(Exception e)
{
System.out.println("enter the N value correctly");
}
}
}