Use the program to explain everything package com.tianyu.summer;
/ ** * @Author Summer * * / import java.util. *;
Public class stacktest {
Public stacktest () {strack stack = new stack ();
Boolean Bool = Boolean.true; Character Character = New Character ('$'); / ** * The stack stack must be pressed into the Object type, so all the types of the previously defined is the subclass of Object * / Try {Stack. Push (Bool); PrintStack; stack.push (character); PrintStack; / ** * When you need to bring a parameter when you want to pop up, you don't need to bring a parameter because the stack is a certain pop-up law, if you bring your own parameters The program will be wrong * / stack.pop (); // printstack; stack.pop (); printstack; stack.pop ();} catch (emptystackedException e) {/ ** * throw Java. Util.emptystackexception at java.util.stack.peek (unknown * Source) at java.util.stack.pop (unknown source) at * com.tianu.summer.stacktest.
Public void printstack (stack stack) {if (stack.Isempty ()) {system.out.println ("stack is empty");} else {system.out.print ("stack contains:"); enumeration items = stack .Elements (); while (items.hasmorelements ()) {system.out.print (items.nextelement () ");} system.out.print (" / n ");}}
Public void removestack (stack stack) {if (stack.Isempty ()) {system.out.println ("stack is empty");} else {system.out.print ("stack contains:"); enumeration items = stack .Elements (); while (items.hasmorelements ()) {system.out.print (items.nextelement () ");} system.out.print (" / n ");}}
Public static void main (string [] args) {new stacktest ();}}