hey , hope u guys doing well . i just want to ask for some help . its not about solving my coding but about understanding in java . my teacher had give me an exercise and ask me to type it using jcreator . i figured it out and the process complete . but the problem is i dont fully understand about the question that i had been gave . can anyone help me explain the coding that i've attach here with adding some comment in the coding ?
so this the first coding .
import java.util.*; class StackDemo { static void showpush(Stack st, int a) { st.push(new Integer(a)); System.out.println("push(" + a + ")"); System.out.println("Stack: " + st); } 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, 42); showpush(st, 66); showpush(st, 99); showpop(st); showpop(st); showpop(st); try { showpop(st); } catch (EmptyStackException e) { System.out.println("empty stack"); } } }
and this is the second conding .
import java.util.*; public class StackDemo1{ public static void main(String[] args) { Stack stack=new Stack(); stack.push(new Integer(10)); stack.push("a"); System.out.println("The contents of Stack is " + stack); System.out.println("The size of an Stack is " + stack.size()); System.out.println("The number poped out is " + stack.pop()); System.out.println("The number poped out is " + stack.pop()); System.out.println("The contents of stack is " + stack); System.out.println("The size of an stack is " + stack.size()); } }