Advertisement
Guest User

ponay

a guest
Feb 18th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. import java.util.*;
  2. public class stack
  3. {
  4. public static void main(String args[])
  5. {
  6. Stack<String> stack = new Stack<String>();
  7. stack.push("bottom");
  8. printStack(stack);
  9. stack.push("second");
  10. printStack(stack);
  11. stack.push("third");
  12. printStack(stack);
  13.  
  14. stack.pop();
  15. printStack(stack);
  16. stack.pop();
  17. printStack(stack);
  18. stack.pop();
  19. printStack(stack);
  20. }
  21.  
  22. private static void printStack(Stack<String> s)
  23. {
  24. if(s.isEmpty())
  25. {
  26. System.out.println("Stack is Empty");
  27. }
  28.  
  29. else
  30. {
  31. System.out.printf("%s TOP\n", s);
  32. }
  33.  
  34.  
  35.  
  36. }
  37.  
  38.  
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement