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