Advertisement
Krassi_Daskalova

Browser History

Jan 26th, 2022
904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. import java.util.ArrayDeque;
  2. import java.util.Scanner;
  3.  
  4. public class BrowserHistory {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         ArrayDeque<String> browser = new ArrayDeque<>();
  9.         String currentURL;
  10.  
  11.         while (!"Home".equalsIgnoreCase(currentURL = scanner.nextLine())){
  12.             if(!"back".equalsIgnoreCase(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.         }
  24.     }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement