BUT2/DEV/DEV3.2/TP04_Piles/Q1Main.java

44 lines
928 B
Java
Raw Permalink Normal View History

2023-10-25 19:48:54 +02:00
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class Q1Main{
public static void main(String[] args) {
ArrayDeque<Integer> liste = new ArrayDeque<>();
int i;
try{
for (i=0; i<args.length; i++){
2023-11-29 16:08:44 +01:00
if (args[i].equals("x") || args[i].equals("/") || args[i].equals("+") || args[i].equals("-")){
2023-10-25 19:48:54 +02:00
int a;
int b;
a = liste.pop();
b = liste.pop();
2023-11-29 16:08:44 +01:00
if(args[i].equals("x")){
2023-10-25 19:48:54 +02:00
liste.push(b*a);
}
if(args[i].equals("/")){
liste.push(b/a);
}
if(args[i].equals("+")){
liste.push(b+a);
}
if(args[i].equals("-")){
liste.push(b-a);
}
}
else{
liste.push(Integer.parseInt(args[i]));
}
}
System.out.println(liste.pop());
}
catch(NoSuchElementException e){
System.out.println("tu ecrit bien");
}
catch(NumberFormatException e){
System.out.println("arretes de mal executer le code");
}
}
}