SHARE
TWEET

Untitled

a guest May 22nd, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. }else {
  2.             System.out.println("Entered to the calculation zone"); // message
  3.             int operatorIndex = 'N';
  4.             char operator;
  5.             for (int i=0; i<expr.length(); i++) {
  6.                 //check the operator
  7.                 operator = expr.charAt(i);
  8.  
  9.                 if (expr.charAt(i) == '+' || expr.charAt(i) == '-') {
  10.                     System.out.println("plus and minus zone");
  11.                     operatorIndex = i;
  12.                     System.out.println(operatorIndex);
  13.                 } else if (expr.charAt(i) == '*' || expr.charAt(i) == '/') {
  14.  
  15.                        // TODO: 5/22/2019  function for kefet and hiluk
  16.                        // return eval("lol from left") * eval("lol from right");
  17.  
  18.                 }
  19.  
  20.             }
  21.             String leftExpr, rightExpr;
  22.             rightExpr = expr.substring(operatorIndex + 1);
  23.             leftExpr = expr.substring(0,operatorIndex);
  24.             System.out.println("Right Expression is " + rightExpr);
  25.             System.out.println("Left Expression is " + leftExpr);
  26.  
  27.             switch (expr.charAt(operatorIndex)){
  28.                 case '+':
  29.                     System.out.println("PLUS");
  30.                     return eval(leftExpr) + eval(rightExpr);
  31.  
  32.                 case '-':
  33.                     System.out.println("MINUS");
  34.                     return eval(leftExpr) - eval(rightExpr);
  35.  
  36.                 default:
  37.                     throw new IllegalStateException("Unexpected value: " + expr.charAt(operatorIndex));
  38.             }
  39.  
  40.  
  41.         }
  42.  
  43.  
  44.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top