-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPerfectPrime.java
More file actions
57 lines (54 loc) · 1.16 KB
/
PerfectPrime.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
import java.io.*;
class Perfect implements Runnable
{
public void run()
{
int no;
for(no=1;no<=1000;no++)
{
int sum=0;
for(int i=1;i<=no/2;i++)
{
if(no%i==0)
sum=sum+i;
}
if(no==sum)
System.out.println(no+" Number is perfect");
}
}
}
class Prime implements Runnable
{
public void run()
{
int no;
for(no=2;no<=1000;no++)
{
int cnt=0;
for(int i=2;i<=no/2;i++)
if(no%i==0)
{
cnt++;
break;
}
if(cnt==0)
System.out.println(no+" Number is prime");
}
}
}
class PerfectPrime
{
public static void main(String args[])
{
try
{
Perfect p=new Perfect();
Thread t1=new Thread(p);
Prime p1=new Prime();
Thread t2=new Thread(p1);
t1.start();
t2.start();
}
catch(Exception e1){}
}
}