Question: how did they get the output?!! public class StackOfIntegers { private int [] elements; private int size; public static final int DEFAULT_CAPACITY =16; 1** Construct

how did they get the output?!!
how did they get the output?!! public class StackOfIntegers \{ private int
[] elements; private int size; public static final int DEFAULT_CAPACITY =16; 1**

public class StackOfIntegers \{ private int [] elements; private int size; public static final int DEFAULT_CAPACITY =16; 1** Construct a stack with the default capacity 16% public StackOfIntegers() \{ this (DEFAULT_CAPACITY); \} ** Construct a stack with the specified capacity public StackofIntegers(int capacity) \{ elements = new int[capacity]; \} 1** Push a new integer into the top of the stack */ public void push(int value) \{ if (size >= elements.length) \{ int[] temp = new int[elements. length * 2]; System.arraycopy(elements, , temp, , elements.length); elements = temp; \} elements [ size ++]= value; \}. I** Return and remove the top element from the stack */ public int pop() \{ return elements[--size]; \}. /** Return the top element from the stack */ public int peek() \{ return elements [size - 1]; \} 1** Test whether the stack is empty */ public boolean isEmpty() \{ return size ==; \} /** Return the number of elements in the stack */ public int getSize() \{ return size; \} \} public class Teststackofintegers \{ public static void main(String[] args) \{ Stackofintegers stack = new StackofIntegers(); for (int i=0;ijavac TestStackofintegers. java Compiled successful JDK18>java TeststackofIntegers 9876543210 JDK18>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!