Source of CountDown.java


  1: //CountDown.java
  2: 
  3: import java.util.Scanner;
  4: 
  5: public class CountDown
  6: {
  7:     private int count;
  8: 
  9:     public static void main(String[] args)
 10:     {
 11:          CountDown countDowner = new CountDown();
 12:          countDowner.getCount();
 13:          countDowner.showCountDown();
 14:     }
 15: 
 16:     public void getCount()
 17:     {
 18:         System.out.print("\nEnter a positive integer: ");
 19:         Scanner keyboard = new Scanner(System.in);
 20:         count = keyboard.nextInt();
 21:         keyboard.nextLine();
 22:         if (count <= 0)
 23:         {
 24:             System.out.println("Input must be positive.");
 25:             System.out.println("Try again.");
 26:             getCount();//start over
 27:         }
 28:     }
 29: 
 30:     public void showCountDown()
 31:     {
 32:         System.out.println("Counting down:");
 33:         for (int left = count; left >= 0; left--)
 34:             System.out.print(left + ", ");
 35:         System.out.println("Blast Off!");
 36:     }
 37: }
 38: