Create a Stack, push the value 1, 4, 6, 9 into it and then pop all the items in
ID: 645141 • Letter: C
Question
Create a Stack, push the value 1, 4, 6, 9 into it and then pop all the items in the stack and print it on the screen.Create a Stack, push the value 1, 4, 6, 9 into it and then pop all the items in the stack and print it on the screen.
Create a Stack, push the value 1, 4, 6, 9 into it and then pop all the items in the stack and print it on the screen.Create a Stack, push the value 1, 4, 6, 9 into it and then pop all the items in the stack and print it on the screen. CAN YOU PLEASE WRITE A JAVA CODE PLEASE !!!!!!!!!!!!!!Explanation / Answer
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
public class StackOps{
public static void main(String args[]){
Stack<Integer> s = new Stack<Integer>();
s.push(new Integer(1));
s.push(new Integer(4));
s.push(new Integer(6));
s.push(new Integer(9));
System.out.print("Stack after pushing all the elements: ");
System.out.println(s);
while(!s.isEmpty()){
s.pop();
}
System.out.print("Stack after popping all the elements: ");
System.out.println(s);
}
}