Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayDeque;
- import java.util.Collections;
- import java.util.List;
- import java.util.Scanner;
- class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- ArrayDeque<String> browser = new ArrayDeque<>();
- String input = sc.nextLine();
- while(!input.equals("Home")) {
- if(input.equals("back")) {
- String current = browser.peek();
- if (current == null) {
- System.out.println("no previous URLs");
- } else {
- current = browser.pop();
- if(browser.isEmpty()) {
- System.out.println("no previous URLs");
- browser.push(current);
- } else {
- System.out.println(browser.peek());
- }
- }
- } else {
- browser.push(input);;
- System.out.println(input);
- }
- input = sc.nextLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement