Advertisement
meteor4o

JA-Stacks-01.BrowserHistory

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