-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChickenVoice.java
More file actions
43 lines (33 loc) · 810 Bytes
/
Copy pathChickenVoice.java
File metadata and controls
43 lines (33 loc) · 810 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
class EggVoice extends Thread {
@Override
public void run() {
for (int i = 0; i < 5; i++) {
try {
sleep(1000);
} catch (InterruptedException e) {}
System.out.println("egg!");
}
}
}
class ChickenVoice {
public static void main(String[] args) {
EggVoice mAnotherOpinion = new EggVoice();
System.out.println("Let's the battle begin...");
mAnotherOpinion.start();
for (int i = 0; i < 5; i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {}
System.out.println("chicken!");
}
if (mAnotherOpinion.isAlive()) {
try {
mAnotherOpinion.join();
} catch (InterruptedException e) {}
System.out.println("First there was the egg!");
} else {
System.out.println("First there was the chicken!");
}
System.out.println("The end!");
}
}