-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEven_Odd.java
More file actions
35 lines (35 loc) · 798 Bytes
/
Even_Odd.java
File metadata and controls
35 lines (35 loc) · 798 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
class Even extends Thread{
@Override
public void run(){
for(int i=1;i<=20;i++){
if(i%2==0){
System.out.print(i+" ");
}
}
System.out.println();
}
}
class Odd extends Thread{
@Override
public void run(){
for(int i=1;i<=20;i++){
if(i%2!=0){
System.out.print(i+" ");
}
}
}
}
public class Even_Odd {
public static void main(String[] args) {
Even e = new Even();
Odd o = new Odd();
e.start();
try {
e.join();
Thread.sleep(1000);
} catch (InterruptedException ex) {
System.out.println("Current Thread Caught");
}
o.start();
}
}