Advertisement
damesova

Browser History Upgrade [Mimi][JA]

May 18th, 2019
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. import java.util.ArrayDeque;
  2. import java.util.Scanner;
  3.  
  4. public class _08_BrowserHistoryUpgrade2 {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner sc = new Scanner(System.in);
  8.  
  9.         ArrayDeque<String> s = new ArrayDeque<>();
  10.         ArrayDeque<String> q = new ArrayDeque<>();
  11.  
  12.         String input = "";
  13.         while (!"Home".equals(input = sc.nextLine())) {
  14.             if (input.equals("back")) {
  15.                 if (s.size() > 1) {
  16.                     q.push(s.pop());
  17.                     String current = s.peek();
  18.                     System.out.println(current);
  19.                 } else {
  20.                     System.out.println("no previous URLs");
  21.                 }
  22.             } else if (input.equals("forward")) {
  23.                 if (!q.isEmpty()) {
  24.                     s.push(q.peek());
  25.                     System.out.println(q.poll());
  26.  
  27.                 } else {
  28.                     System.out.println("no next URLs");
  29.                 }
  30.             } else {
  31.                 if (!q.isEmpty()) {
  32.                     q.clear();
  33.                 }
  34.                 s.push(input);
  35.                 System.out.println(s.peek());
  36.             }
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement