Running the Example
Home ] Up ] Example ] [ Running the Example ]

 

 

Yet again, absolutely no changes were necessary in the StackTest class:

package anonymousClasses;
import java.util.Enumeration;
/**
 * Tests the Stack and StackIterator classes
 */
public class StackTest
{
  /**
   * Main entry point
   */
  public static void main(String[] args)
  {
    Stack aStack = new Stack(10);
    for (int i = 0; i < aStack.getMaxStackSize(); i++)
      aStack.push(i*i);
    Enumeration enumerator = aStack.getEnumerator();
    while (enumerator.hasMoreElements())
    {
      int value = (Integer) enumerator.nextElement();
      System.out.print(" " + value);
    }
    System.out.println();
  }
}

When run, this program outputs the same values as before:

 0 1 4 9 16 25 36 49 64 81
 

This page was last modified on 02 October, 2007