Krolyxon
Commit 2a9918f

Branches

Refs →

jcal2a9918f

fix substraction bug

Author
krolxon
Date
2024-02-14 23:17 +0530
Parent
be3ed51
Commit
2a9918ffb5727d8e9d405115fc074451693daf8b

+3 −3

2 files changed

  1. M Calculator.java +1 −1
  2. M Parser.java +2 −2
M Calculator.java View
@@ -1,6 +1,6 @@
11 public class Calculator {
22 public static void main(String[] args) {
3− String expr = "(36 * 3 + 9 * 7) * (84 / 12) * 5";
3+ String expr = "(84 / 4 * 3 - 9) * 2 + 1 / 5"; // 108.2
44 Parser p = new Parser(expr);
55 String postfix = p.toPostFix();
66 System.out.println(p.evalExpr(postfix));
M Parser.java View
@@ -1,5 +1,4 @@
11 /* Todo
2−* - Fix Substraction errors
32 * - Add support for trigonometric functions
43 * - Remove all edge cases
54 */
@@ -17,6 +16,7 @@ public class Parser {
1716
1817 public static boolean isOperand(char c) {
1918 switch (c) {
19+ case '0':
2020 case '1':
2121 case '2':
2222 case '3':
@@ -115,7 +115,7 @@ public class Parser {
115115 case '+':
116116 return op2 + op1;
117117 case '-':
118− return op2 - op1;
118+ return op1 - op2;
119119 case '*':
120120 return op2 * op1;
121121 case '/':