- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPerfectPrime.java
More file actions
Latest commit
57 lines (54 loc) · 1.16 KB
/
Copy pathPerfectPrime.java
File metadata and controls
57 lines (54 loc) · 1.16 KB
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
57
importjava.io.*;
classPerfectimplementsRunnable
{
publicvoidrun()
{
intno;
for(no=1;no<=1000;no++)
{
intsum=0;
for(inti=1;i<=no/2;i++)
{
if(no%i==0)
sum=sum+i;
}
if(no==sum)
System.out.println(no+" Number is perfect");
}
}
}
classPrimeimplementsRunnable
{
publicvoidrun()
{
intno;
for(no=2;no<=1000;no++)
{
intcnt=0;
for(inti=2;i<=no/2;i++)
if(no%i==0)
{
cnt++;
break;
}
if(cnt==0)
System.out.println(no+" Number is prime");
}
}
}
classPerfectPrime
{
publicstaticvoidmain(Stringargs[])
{
try
{
Perfectp=newPerfect();
Threadt1=newThread(p);
Primep1=newPrime();
Threadt2=newThread(p1);
t1.start();
t2.start();
}
catch(Exceptione1){}
}
}