Skip to main content

java collections programing help

1 reply [Last post]
kowshik121
Offline
Joined: 2011-06-24
Points: 0

How to evaluate 1+2*3+4/2-2 arthematic expression by taking input as a string using operator priority

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
RodionGork
Offline
Joined: 2011-07-02
Points: 0

Google: "parsing arithmetic expressions"

Firstly you would need to split the string into meaningful lexems (numbers, signs). This could be done in more than one way. However it is not complex problem.

Secondly you need to process them, applying arithmetic rules. You would find that priority is often managed via recursion according to backus-naur rules for your case, or via translating to Reverse Polish Notation and then simply evaluating it.

P.S. Why, by the way, have you chosen such obscure title for your question?