mathiaspl20

countdown

Oct 4th, 2017
67
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. import java.util.Timer;
  3. import java.util.TimerTask;
  4. public class Countdown {
  5. ////10-->0
  6. static int interval;
  7. static Timer timer;
  8. //
  9. public static void main(String[] args) {
  10. // for ( int potato = 10; potato >= 0; potato-- ){
  11. // System.out.println(potato);
  12. // }
  13. //}
  14. Scanner sc = new Scanner(System.in);
  15. System.out.print("Input seconds => : ");
  16. String secs = sc.nextLine();
  17. int delay = 1000;
  18. int period = 1000;
  19. timer = new Timer();
  20. interval = Integer.parseInt(secs);
  21. System.out.println(secs);
  22. timer.scheduleAtFixedRate(new TimerTask() {
  23.  
  24. public void run() {
  25. System.out.println(setInterval());
  26.  
  27. }
  28. }, delay, period);
  29. }
  30.  
  31. private static final int setInterval() {
  32. if (interval == 1)
  33. timer.cancel();
  34. return --interval;
  35. }
  36. }
RAW Paste Data