-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOddEven.java
More file actions
51 lines (39 loc) · 1.17 KB
/
OddEven.java
File metadata and controls
51 lines (39 loc) · 1.17 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
class Odd implements Runnable{
@Override
public void run(){
try {
Thread.sleep(3000);
for (int i = 1; i <=10; i=i+2) {
System.out.println("Odd Number "+i);
}
} catch (InterruptedException ex) {
}
System.out.println(Thread.currentThread().getName());
}
}
class Even implements Runnable{
@Override
public void run(){
try {
Thread.sleep(1000);
for (int i = 0; i <=10; i=i+2) {
System.out.println("Even Number "+i);
}
} catch (InterruptedException e) {
}
System.out.println(Thread.currentThread().getName());
}
}
public class OddEven{
@SuppressWarnings("static-access")
public static void main(String[] args) throws InterruptedException {
System.out.println(Thread.currentThread().getName());
Odd o = new Odd();
Thread t1=new Thread(o);
Even e= new Even();
Thread t2=new Thread(e);
t1.start();
t2.start();
t2.sleep(1000);
}
}