/*
   This program demonstates using a "partially full array" by reading
   in up to 100 positive integers from the user and printing them in
   reverse order.  Input ends when the user enters a non-positive integer.
*/

public class ReverseInputNumbers {

   public static void main(String[] args) {
  
      int[] numbers;  // An array for storing the input values.
      int numCt;      // The number of numbers saved in the array.
      int num;        // One of the numbers input by the user.
    
      numbers = new int[100];   // Space for 100 ints.
      numCt = 0;                // No numbers have been saved yet.
    
      TextIO.putln("Enter up to 100 positive integers; Enter 0 to end");
    
      while (true) {   // Get the numbers and put them in the array.
         TextIO.put("? ");
         num = TextIO.getlnInt();
         if (num <= 0)
            break;
         numbers[numCt] = num;
         numCt++;
      }
    
      TextIO.putln("\nYour numbers in reverse order are:\n");
    
      for (int i = numCt - 1; i >= 0; i--) {
          TextIO.putln( numbers[i] );
      }
    
   } // end main();
  
}  // end class ReverseInputNumbers
