Convert String to operator(+*/-) in java

前端 未结 5 1293
时光说笑
时光说笑 2021-01-06 05:57

I am using Stack class to calculate simple arithmetic expressions involving integers, such as 1+2*3.your program would execute operations in the order given,without regardin

5条回答
  •  误落风尘
    2021-01-06 06:37

    Do what Ogen suggested and manually check the operator. A quick shortcut to doing the if, else if .... structure is switch, that is

    switch(operand) {
    case "*":
          break;
    case "+":
          break; 
     .....
     default:
    }
    

提交回复
热议问题