-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountdownTimer.java
More file actions
35 lines (27 loc) · 961 Bytes
/
CountdownTimer.java
File metadata and controls
35 lines (27 loc) · 961 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
import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;
public class CountdownTimer {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
//COUNTDOWN TIMER PROGRAM
final int[] count = {0};//Used "final" coz it is used within the class.
System.out.print("Where to start the countdown timer from? : ");
count[0]=scanner.nextInt();
Timer timer = new Timer();
TimerTask Task = new TimerTask(){
@Override
public void run(){
if(count[0] ==0){
System.out.println("HAPPY NEW YEAR...✨");
timer.cancel();
}
else if(count[0] >0){
System.out.println(count[0]);
count[0] -=1;
}
}
};
timer.schedule(Task,0,1000);
}
}