SHARE
TWEET

lab_8.Browser History Upgrade

nikeza Sep 18th, 2019 104 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 queue1_Lab_8Browser_History_Upgrade {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         String input = scanner.nextLine();
  8.  
  9.         ArrayDeque<String> stack = new ArrayDeque<>();
  10.         ArrayDeque<String> stakFW = new ArrayDeque<>();
  11.  
  12.  
  13.         while (!input.equals("Home")) {
  14.  
  15.             if (input.equals("back")) {
  16.  
  17.                 if (stack.size() > 1) {
  18.  
  19.                     String url = stack.pop();
  20.                     stakFW.push(url);
  21.                     System.out.println(stack.peek());
  22.                    
  23.                 } else {
  24.                     System.out.println("no previous URLs");
  25.                 }
  26.             } else if (input.equals("forward")) {
  27.  
  28.                 if (stakFW.isEmpty()) {
  29.                     System.out.println("no next URLs");
  30.                 } else {
  31.                     String url = stakFW.pop();
  32.                     System.out.println(url);
  33.                     stack.push(url);
  34.  
  35.                 }
  36.             } else {
  37.                 stakFW.clear();
  38.                 stack.push(input);
  39.                 System.out.println(stack.peek());
  40.             }
  41.  
  42.             input = scanner.nextLine();
  43.         }
  44.  
  45.  
  46.      
  47.  
  48.  
  49.     }
  50.  
  51.  
  52. }
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