Advertisement
deyanmalinov

01. Browser History

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