fin tp piles

This commit is contained in:
Simoes Lukas
2025-11-03 11:08:37 +01:00
parent 63a15fc6c7
commit 9c4ca5bcda
14 changed files with 211 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
import java.awt.*;
import java.util.ArrayDeque;
public class Main {
public static void main(String[] args) {
ArrayDeque<String> pile = new ArrayDeque<>(args.length);
for (int i = 0; i != args.length; i++) {
try {
Integer.parseInt(args[i]);
pile.addFirst(args[i]);
} catch (NumberFormatException e) {
int n2 = Integer.parseInt(pile.removeFirst());
int n1 = Integer.parseInt(pile.removeFirst());
System.out.println(n2);
System.out.println(n1);
switch (args[i]) {
case "+":
pile.addFirst(n1 + n2 + "");
break;
case "-":
pile.addFirst(n1 - n2 + "");
break;
case "x":
pile.addFirst(n1 * n2 + "");
break;
case "/":
pile.addFirst(n1 / n2 + "");
}
}
}
System.out.println("= " + pile.removeFirst());
}
}