Search code examples
javarpn

java rpn calculator


i would like to include a simple RPN type calculator function in one of my projects.

basically i need a method that can convert for example:

"30 / ((1 + 4) * 3)" into "2"

does anyone know of any pre-written libs that can do this?

thanks.


Solution

  • You should implement Shunting Yard Algorithm

    also look : Reverse Polish notation

    You can use Shunting Yard (Jep API)

    I suggest you to write it in python if you don't have to implement it in Java because of it's built-in methods

    print eval("30 / ((1 + 4) * 3)")
    

    ideone demo