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 …

## All 4 Replies

stultuske
1,116
Posting Maven
Featured Poster

hszforu
-3
Junior Poster in Training

JamesCherrill
4,334
Most Valuable Poster
Moderator
Featured Poster

hszforu
-3
Junior Poster in Training

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.