Advertisement
jackyhuichunkit

Untitled

Feb 20th, 2020
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. class stackdemo {
  4.     public static Stack<Integer> S = new Stack<Integer>();
  5.  
  6.     public static void main(String[] args) {
  7.         int temp;
  8.  
  9.         S.push(3);
  10.         S.push(4);
  11.         S.push(1);
  12.         S.push(10);
  13.         S.push(20);
  14.         S.push(30);
  15.  
  16.         System.out.println("1st element poped from the stack:");
  17.         temp = S.pop();
  18.         System.out.println(temp);
  19.  
  20.         System.out.println("2nd element poped from the stack:");
  21.         temp = S.pop();
  22.         System.out.println(temp);
  23.  
  24.         System.out.println("Remaining elements");
  25.         while (!S.empty()) {
  26.             System.out.println(S.pop());
  27.         }
  28.     }
  29.  
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement