-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClock.java
More file actions
65 lines (58 loc) · 1.34 KB
/
Clock.java
File metadata and controls
65 lines (58 loc) · 1.34 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class TSec implements Runnable {
int s = 0;
@Override
public void run() {
while (true) {
try {
Thread.sleep(1000);
s = (s + 1) % 60;
System.out.println("s : " + s);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class TMin implements Runnable {
int m = 0;
@Override
public void run() {
while (true) {
try {
Thread.sleep(60000);
m = (m + 1) % 60;
System.out.println("m : " + m);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class THour implements Runnable {
int h;
@Override
public void run() {
while (true) {
try {
Thread.sleep(3600000);
h = (h + 1) % 24;
System.out.println("s : " + h);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
/**
* Clock
*/
public class Clock {
public static void main(String[] args) {
Thread s = new Thread(new TSec());
Thread m = new Thread(new TMin());
Thread h = new Thread(new THour());
h.start();
m.start();
s.start();
}
}