So here is something i am trying to do:

1.Store a mathematical expression eg. 23*32+12 in the String datatype.

2.Now i have to calculate the value of that expression.

So i thought of converting the string to integer using parseInt , but for this the string need not contain *,+ and other operators.So how can i calculate the value of that expression?

## Recommended Answers

Jump to Postwith the indexOf method, you'll be able to detect where there are mathematical symbols, such as * + /

next, use the substring method, to divide the String you have, and run the Integer.parseInt method on the substrings you've found.

but make sure you only have non-decimal numbers, otherwise, an …

Jump to PostNormally you would have a stack where you can push values and operators as you parse them, and pop them when it's time time to execute each operator.