Write a method “removeBottomItemStack” that takes a stack of integers and removes the first item added (the one at the bottom).
Please use Java
- Write a method “removeBottomItemStack” that takes a stack of integers and removes the first item added (the one at the bottom).
Step 1 : Start
Step 2 : Define a method removeBottomItemStack which removes the Bottom Element of the Stack it receives as an argument using the remove() method.
Step 3 : In the main method declare a stack of Integers.
Step 4 : Adding 5 elements in the stack 1 , 2 , 3 , 4 , 5 using the add() method.
Step 5 : Printing the Initial Stack.
Step 6 : Calling the removeBottomItemStack() method while passing the created stack of integers as argument.
Step 7 : The removeBottomItemStack() method removes the first element of the stack using the remove() method with the index as : 0. i.e. myStack.remove(0);
Step 8 : Printing the Element removed from the Stack.
Step 9 : Printing the Final Stack.
Step 10 : Stop
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images