Program 2
Program 2
Develop a JAVA
main method to illustrate Stack operations.
package lab.stack;
Output:
Pushing integers onto the stack:
0 pushed onto stack.
1 pushed onto stack.
2 pushed onto stack.
3 pushed onto stack.
4 pushed onto stack.
5 pushed onto stack.
6 pushed onto stack.
7 pushed onto stack.
8 pushed onto stack.
9 pushed onto stack.
Stack after pushing:
Stack elements: 0 1 2 3 4 5 6 7 8 9
Popping integers off the stack:
9 popped from stack.
Stack after pop:
Stack elements: 0 1 2 3 4 5 6 7 8
8 popped from stack.
Stack after pop:
Stack elements: 0 1 2 3 4 5 6 7
7 popped from stack.
Stack after pop:
Stack elements: 0 1 2 3 4 5 6
6 popped from stack.
Stack after pop:
Stack elements: 0 1 2 3 4 5
5 popped from stack.
Stack after pop:
Stack elements: 0 1 2 3 4