Advertisement
Krassi_Daskalova

Browser History

Jan 26th, 2022
980
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. import java.util.ArrayDeque;
  2. import java.util.Scanner;
  3.  
  4. public class BrowserHistory2 {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         ArrayDeque<String> browser = new ArrayDeque<>();
  9.         String currentURL = scanner.nextLine();
  10.  
  11.         while (!"Home".equals(currentURL)){
  12.             if(!"back".equals(currentURL)){
  13.                 browser.push(currentURL);
  14.                 System.out.println(currentURL);
  15.             } else {
  16.                 if(browser.size() > 1){
  17.                     browser.pop();
  18.                     System.out.println(browser.peek());
  19.                 } else {
  20.                     System.out.println("no previous URLs");
  21.                 }
  22.             }
  23.             currentURL = scanner.nextLine();
  24.         }
  25.  
  26.     }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement