我在下面的代码中遇到了非常困难的事情......我试图让苹果、橙子和香蕉显示为推、拉和窥视。但是,我不断得到0
import java.util.*;
public class GenericStackApp {
private static int apple;
private static int banana;
private static int orange;
static void showpush(Stack st, int apple)
{
st.push(new Integer(apple + banana + orange));
System.out.println("push(" + apple + banana + orange + ")");
System.out.println("stack: " + apple + banana + orange );
}
static void showpop(Stack st)
{
System.out.print("pop -> ");
Integer a = (Integer) st.pop();
System.out.println(a);
System.out.println("stack: " + st);
}
public static void main(String args[])
{
Stack st = new Stack();
System.out.println("stack: " + st);
showpush(st, apple);
showpush(st, banana);
showpush(st, orange);
showpop(st);
showpop(st);
showpop(st);
try
{
showpop(st);
} catch (EmptyStackException e)
{
System.out.println("3 items in the stack");
}
}
}
先感谢您。