java countdown timer

Solutions on MaxInterview for java countdown timer by the best coders in the world

showing results for - "java countdown timer"
Victoria
14 May 2016
1import java.util.Scanner;
2import java.util.Timer;
3import java.util.TimerTask;
4
5public class Stopwatch {
6static int interval;
7static Timer timer;
8
9public static void main(String[] args) {
10    Scanner sc = new Scanner(System.in);
11    System.out.print("Input seconds => : ");
12    String secs = sc.nextLine();
13    int delay = 1000;
14    int period = 1000;
15    timer = new Timer();
16    interval = Integer.parseInt(secs);
17    System.out.println(secs);
18    timer.scheduleAtFixedRate(new TimerTask() {
19
20        public void run() {
21            System.out.println(setInterval());
22
23        }
24    }, delay, period);
25}
26
27private static final int setInterval() {
28    if (interval == 1)
29        timer.cancel();
30    return --interval;
31}
32}
33Try this.