Skip to content
Advertisement

Prefix To Postfix Java

I need some help with my prefix to postfix code. When ever I generate the action through GUI from the expression “* 2 + 2 – + 12 9 2” it returns 2*. It should be returning “2 2 12 9 + 2 -+*”. I keep changing the code around and I keep ending up with the same result. Please I would appreciate any guidance.

JavaScript

Advertisement

Answer

your problem is you don’t consider the delimiters you have in your expression, which are the spaces between each sub expressions.

I suggest for you not working on the original string with the delimiters, just split your string to the arguments and work on that array, and join them later with your preferred delimiter.

anyway, here is the fixed code:

JavaScript

}

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement