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