// file:    utilStack.java
// author:  Robert Keller 
// purpose: Illustrating the use of class Stack in java.util.
//          Contrast with Stack.java which was a custom stack for int's.
//
//          Here we have a stack of Object's, so we need to first "wrap"
//          the int's, then unwrap them later.

import java.io.*;
import java.util.*;		// to get Stack class

class utilStack			// This only houses the test program
{
// Test program, enter limit > 0 and cycles on command line

public static void main(String arg[])
  {
  // take arguments from command line (1 required)

  if( arg.length < 1 )
    {
    System.err.println("One argument is required, cycles");
    System.exit(1);
    }
  int cycles = new Integer(arg[0]).intValue();

  Stack s = new Stack();
  for( int i = 0; i < cycles; i++ )
    {
    s.push(new Integer(i));		// wrap the int in an object
    }
  while( !s.empty() )
    {
    System.out.println(s.pop());	// print the int popped
    }
  }
}

