Advertisement
Tsuki11

incorrect

Apr 10th, 2020
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. import java.util.ArrayDeque;
  2. import java.util.Scanner;
  3. // 100 / 100
  4.  
  5. public class Lab_Task_8_BrowserHistoryUpgrade_1_1 {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         ArrayDeque<String> stackUrl = new ArrayDeque<>();
  9.         ArrayDeque<String> forwardStack = new ArrayDeque<>();
  10.         String input = "";
  11.         while (!"Home".equals(input = scanner.nextLine())) {
  12.             if ("back".equals(input)) {
  13.  
  14.                 if (stackUrl.size() > 1) {
  15.                     String toRemove = stackUrl.pop();
  16.                     forwardStack.push(toRemove);
  17.                     System.out.println(stackUrl.peek());
  18.  
  19.                 } else {
  20.                     System.out.println("no 100 ot 100 URLs");
  21.                 }
  22.                 continue;
  23.             }
  24.             if ("forward".equals(input)) {
  25.  
  26.                 if (forwardStack.size() > 0) {
  27.                     String currentForward = forwardStack.pop();
  28.                     System.out.println(currentForward);
  29.                     stackUrl.push(currentForward);
  30.                 } else {
  31.                     System.out.println("no next URLs");
  32.                 }
  33.                 continue;
  34.             }
  35.             System.out.println(input);
  36.             stackUrl.push(input);
  37.             forwardStack.clear();
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement