-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathodd_even_thread.java
More file actions
56 lines (47 loc) · 901 Bytes
/
odd_even_thread.java
File metadata and controls
56 lines (47 loc) · 901 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
public class odd_even_thread {
public static void main(String[] args) {
oddthread o = new oddthread();
eventhread et = new eventhread();
o.start();
try {
o.join();
}
catch(Exception e) {
System.out.println(e);
}
et.start();
try {
et.join();
}
catch(Exception e) {
System.out.println(e);
}
}
}
class oddthread extends Thread {
public void run() {
try {
System.out.print("Odd Numbers : ");
for(int i=1;i<=100;i+=2)
{
System.out.print(i+" ");
}
System.out.println();
}
catch(Exception e) {
System.out.print(e);
}
}
}
class eventhread extends Thread {
public void run() {
try {
System.out.print("Even Numbers : ");
for(int i=2;i<=100;i+=2) {
System.out.print(i+" ");
}
System.out.println();
}
catch(Exception e) {System.out.print(e);}
}
}