title: Write a Java program that prompts for a number and counts down from that number
body: <p>I have to write a code where it prompts the user to input a number, and it should count down from the number to 0. I am given this:
  There are three required functions, main(), doCountDown(), and
  waitASec(). Optionally, a fourth function will perform user
  interaction.
  So far, this is what I have. There are no errors and the code runs. However, the countdown does not stop at 0, it continuously counts down into negative numbers. I am not sure where to go from here.</p>
  
  <pre><code>import java.util.Date;
  import java.util.Scanner;
  
  public class Code {
  
      public static void main(String[] args) {
          System.out.println("Count down how many seconds? ");
          Scanner sc = new Scanner(System.in);
          int num = sc.nextInt();
          sc.close();
          doCountDown(num);
      }
      public static void doCountDown(int num){
          for(int i=num;i&lt;=num;i--){
              System.out.println(i);
              waitASec();
          }
      }
      private static void waitASec() {
          long t = new Date().getTime();
          long t1=t+1000;
          for(;t&lt;t1;) {
              t = new Date().getTime();
          }
      }
  
  }
  </code></pre>