-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStopWatch.java
More file actions
37 lines (29 loc) · 854 Bytes
/
StopWatch.java
File metadata and controls
37 lines (29 loc) · 854 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
package threads;
public class StopWatch extends Thread{
public void start(){
int hours =0;
int minutes = 0;
int seconds = 0;
while(true){
try{
// Sleep the main thread for a second
Thread.sleep(100);
// Increment the seconds
seconds ++;
if (seconds == 60){
// Increment the minutes
minutes++;
seconds = 0;
}
if (minutes == 60){
// Increment the hours
hours++;
minutes = 0;
}
System.out.println(hours + ":" + minutes + ":" + seconds);
} catch(InterruptedException e) {
e.printStackTrace();
}
}
}
}