fix substraction bug
This commit is contained in:
parent
be3ed51907
commit
2a9918ffb5
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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 '/':
|
||||
|
|
|
|||
Reference in New Issue