diff options
| author | krolxon <krolyxon@tutanota.com> | 2024-02-14 23:17:41 +0530 |
|---|---|---|
| committer | krolxon <krolyxon@tutanota.com> | 2024-02-14 23:17:41 +0530 |
| commit | 2a9918ffb5727d8e9d405115fc074451693daf8b (patch) | |
| tree | b281c2d24e983a2f307643dea17c1cebd4967a98 | |
| parent | be3ed5190773c168d101425fc9b6dbfbc754fa6b (diff) | |
fix substraction bug
| -rw-r--r-- | Calculator.java | 2 | ||||
| -rw-r--r-- | Parser.java | 4 |
2 files changed, 3 insertions, 3 deletions
diff --git a/Calculator.java b/Calculator.java index 492a572..031fa57 100644 --- a/Calculator.java +++ b/Calculator.java @@ -1,6 +1,6 @@ public class Calculator { public static void main(String[] args) { - String expr = "(36 * 3 + 9 * 7) * (84 / 12) * 5"; + String expr = "(84 / 4 * 3 - 9) * 2 + 1 / 5"; // 108.2 Parser p = new Parser(expr); String postfix = p.toPostFix(); System.out.println(p.evalExpr(postfix)); diff --git a/Parser.java b/Parser.java index 8135393..c588052 100644 --- a/Parser.java +++ b/Parser.java @@ -1,5 +1,4 @@ /* Todo -* - Fix Substraction errors * - Add support for trigonometric functions * - Remove all edge cases */ @@ -17,6 +16,7 @@ public class Parser { public static boolean isOperand(char c) { switch (c) { + case '0': case '1': case '2': case '3': @@ -115,7 +115,7 @@ public class Parser { case '+': return op2 + op1; case '-': - return op2 - op1; + return op1 - op2; case '*': return op2 * op1; case '/': |
