0

how I can evaluate that infix expression in java : ((1)2/4+2-1). I knew that I can use 2 stacks : 1 1st for characters(+-/). 2nd for integers.

then check for priorities of the characters and calculate simultaneously!?

So is there a more perfect way for calculating like that expression?! ..

Thanks,

1 Answers1

1

Are you writing a calculator? Look at Reverse Polish Notation for this algorithm (that might help you). You can also use third-party library for this or dynamic language (Javascript Engine/Groovy/BeanShell/Google: java calculator library/etc.)

Xeon
  • 5,949
  • 5
  • 31
  • 52