-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththread_prac17.java
40 lines (34 loc) · 912 Bytes
/
thread_prac17.java
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
//WAP Which Prints odd and even number from 1 to 10 using thread
//Condition:- First Odd numbers should be printed and than even.
class Odd extends Thread {
public void run() {
System.out.println("----------Odd----------");
for (int i = 1; i <= 5; i++) {
if (i % 2 != 0) {
System.out.println(i); // Prints Odd Number
}
}
}
}
class Even extends Thread {
public void run() {
System.out.println("----------Even----------");
for (int i = 1; i <= 5; i++) {
if (i % 2 == 0) {
System.out.println(i); // Prints Even Number
}
}
}
}
class Demo {
public static void main(String[] args) {
Odd o = new Odd();
Even e = new Even();
o.start();
try {
o.join();
} catch (Exception e1) {
}
e.start();
}
}