fin tp piles
This commit is contained in:
37
DEV3.2/TP04/03_Tableau/Main.java
Normal file
37
DEV3.2/TP04/03_Tableau/Main.java
Normal file
@@ -0,0 +1,37 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
PileTableau<String> pile = new PileTableau<>();
|
||||
|
||||
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());
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user