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?
hszforu
-3
Junior Poster in Training
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,733
Most Valuable Poster
Team Colleague
Featured Poster
hszforu
-3
Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.