|
You don't need stringtokenizer here. Just read your line as a string. Then create a loop which will go over all characters of the string. Append each character to a temporary stringbuffer (stringbufferLeftExpression) until you find one of the operators. Then save operator type and in a similar way, find the right expression by appending characters to a temporary stringbuffer (stringbufferRightExpression). When you find the next operator, apply previous operation on stringbufferLeftExpression and stringbufferRightExpression and save the result to stringbufferLeftExpression. This loop goes like this until whole operation is finished.
I try to explaing it without writing the code. Try it yourself if you understand it. If something is unclear let me know.
|