ihsan1

queue+scanner2

May 15th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. package semester2;
  2. import java.util.*;
  3. public class Kelompok {
  4.          public static void main(String[] args) {
  5.         int k=1;
  6.         Stack<Integer> stack=new Stack<Integer>();
  7.         Queue<Integer> queue=  new LinkedList<Integer>();
  8.         Scanner sc =new Scanner(System.in);
  9.         do
  10.         {
  11.             int j=0,i,ent;
  12.             System.out.println("Tekan 1 untuk Stack dan 2 untuk Queue");
  13.             j=sc.nextInt();
  14.             if(j==1)
  15.             {
  16.                 System.out.println("Tekan 1 untuk Push dan 2 untuk Pop");
  17.                 i=sc.nextInt();
  18.                 if(i==1)
  19.                 {
  20.                     System.out.println("Masukan angka");
  21.                     ent =sc.nextInt();
  22.                     stack.push(ent);
  23.                     System.out.println(stack);
  24.                 }
  25.                 else
  26.                 {
  27.                     stack.pop();
  28.                     System.out.println(stack);
  29.                 }
  30.             }
  31.             else
  32.             {
  33.                 System.out.println("Tekan 1 untuk Push dan 2 untuk Pop");
  34.                 i=sc.nextInt();
  35.                 if(i==1)
  36.                 {
  37.                     System.out.println("Masukan angka");
  38.                     ent =sc.nextInt();
  39.                     queue.add(ent);
  40.                     System.out.println(queue);
  41.                 }
  42.                 else
  43.                 {
  44.                     queue.remove();
  45.                     System.out.println(queue);
  46.                 }
  47.             }
  48.             System.out.println("press 1 to continue and 0 to exit");
  49.             k=sc.nextInt();
  50.         }while(k==1);
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment