Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package StacksAndQueues;
- import java.util.ArrayDeque;
- import java.util.Scanner;
- public class PrinterQueue {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- ArrayDeque<String> queue = new ArrayDeque<>();
- String command = scanner.nextLine();
- while (!"print".equals(command)){
- if ("cancel".equals(command)){
- if (queue.isEmpty()){
- System.out.println("Printer is on standby");
- }else {
- System.out.println("Canceled "+ queue.poll());
- }
- }else {
- queue.offer(command);
- }
- command = scanner.nextLine();
- }
- for (String element : queue) {
- System.out.println(element);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement