-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerfect1.java
More file actions
56 lines (54 loc) · 987 Bytes
/
Copy pathPerfect1.java
File metadata and controls
56 lines (54 loc) · 987 Bytes
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
47
48
49
50
51
52
53
54
55
56
import java.util.*;
public class Perfect1
{
int num;
Perfect1(int nn)
{
num=nn;
}
int sa=1;
/*public int sum_of_factors(int i)
{
int j=2;
if(i==0)
return sa;
else if(j==i)
return sa;
else if(i%j==0)
{
sa=sa+j++;
}
return sum_of_factors(i/j);
}*/
int sum=1,j=2;
int sum_of_factors(int i)
{
if(j==i)
return sum;
else if(i%j==0)
{
sum+=j;
j++;
sum_of_factors(i);
}
else
{
j++;
sum_of_factors(i);
}
return sum;
}
void check()
{
int s=sum_of_factors(num);
if(s==num)
System.out.println("The number is a Perfect1 number");
else
System.out.println("The number is not a Perfect1 number");
}
public static void main(int a)
{
Perfect1 ob=new Perfect1(a);
ob.check();
}
}