blob: 43804c3ef4d131b9ae890d482af70718eb12921d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
public class Calculator {
public static void main(String[] args) {
String expr = "(84 / 4 * 3 - 9) * 2 + 1 / 5"; // 108.2
Parser p;
if (args.length == 0) {
p = new Parser(expr);
} else {
p = new Parser(args[0]);
}
String postfix = p.toPostFix();
// System.out.println("pfix => \t " + postfix);
System.out.println(p.evalExpr(postfix));
}
}
|