Source of CountDown.java


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