-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrowserHistory.java
More file actions
29 lines (26 loc) · 888 Bytes
/
Copy pathBrowserHistory.java
File metadata and controls
29 lines (26 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package StacksAndQueues_Lab;
import java.util.ArrayDeque;
import java.util.Scanner;
public class BrowserHistory {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
ArrayDeque <String> stack = new ArrayDeque<>();
String URL = scan.nextLine();
String current = "";
while(!URL.equals("Home")) {
if (!URL.equals("back")) {
stack.push(URL);
System.out.println(stack.peek());
}else{
if(!stack.isEmpty()) {
current = stack.pop();
System.out.println(stack.peek());
}else{
System.out.println("no previous URLs");
stack.push(current);
}
}
URL = scan.nextLine();
}
}
}