SHARE
TWEET

Untitled

a guest May 19th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayDeque;
  2. import java.util.Scanner;
  3.  
  4. public class P08BrowserHistoryUpgrade {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         ArrayDeque<String> history = new ArrayDeque<>();
  9.         ArrayDeque<String> forwardPages = new ArrayDeque<>();
  10.  
  11.         String input = "";
  12.  
  13.         while (!"Home".equals(input = scanner.nextLine())) {
  14.             if ("back".equals(input)) {
  15.                 if (history.size() > 1) {
  16.                     forwardPages.push(history.pop());
  17.                     System.out.println(history.peek());
  18.                 } else {
  19.                     System.out.println("no previous URLs");
  20.                 }
  21.             } else if ("forward".equals(input)) {
  22.                 if (!forwardPages.isEmpty()) {
  23.                     System.out.println(forwardPages.peek());
  24.                     history.push(forwardPages.pop());
  25.                 } else {
  26.                     System.out.println("no next URLs");
  27.                 }
  28.             } else {
  29.                 history.push(input);
  30.                 System.out.println(input);
  31.                 forwardPages.clear();
  32.             }
  33.         }
  34.     }
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top