Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Solve an equation given a String

807588Mar 26 2009 — edited Apr 29 2009
Hi all,

I'm creating a method that I could pass a String, such as "(5 + 7) / 3" and it would be able to pass back a result, in this case "4".

Eventually I'd also like to add simple variable substitution, so I can pass in "(5 + 7) / X", and tell it X = 3, and have it return "4".

I've just started, and I can see several ways forward, but it seems like it's going to be quite complex. It also seems like this must be something that people have done in the past -- I feel like I'm reinventing the wheel here.

Does anyone know of any examples or libraries that can be used to do this? Maybe I could even use reflection in some way to get Java to simply interpret the result, exactly as if I had typed it in.

Any thoughts?
Thanks!

Tim
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 27 2009
Added on Mar 26 2009
7 comments
946 views