java - Generic Stack assistance -


i having hard time below code... trying apple, orange, , banana show push, pull, , peek. however, keep getting 0's

   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 = (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 stack");            }         }     } 

thank in advance.

you need initialize variables apple, banana , orange this:

     private static int apple = 1;      private static int banana = 2;      private static int orange = 3; 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -