deyanmalinov

06. Hot Potato

May 17th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. package DPM;
  2.  
  3. import java.util.ArrayDeque;
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.     public static void main(String[] args){
  8.         Scanner scan = new Scanner(System.in);
  9.         ArrayDeque<String> queue = new ArrayDeque<>();
  10.         String line ;
  11.  
  12.         while (!"print".equalsIgnoreCase(line= scan.nextLine())){
  13.  
  14.             if (!line.equals("cancel")){
  15.                 queue.offer(line);
  16.  
  17.  
  18.             }else {
  19.                 if (queue.size() !=0){
  20.                     System.out.println("Canceled " + queue.poll());
  21.                 }else {
  22.                     System.out.println("Printer is on standby");
  23.                 }
  24.             }
  25.         }
  26.         while (queue.size() != 0){
  27.             System.out.println(queue.poll());
  28.         }
  29.     }
  30. }
Add Comment
Please, Sign In to add comment