1 Reply Latest reply: Oct 2, 2008 3:20 AM by 800282 RSS

    how can i perform operations on a string written as an algebraic expression

    807589
      i need help...how can i have a program that a string like this ---"1 + 2 + 3"---could be read as integers and you can actually come to a single result using the precedence of operations...
        • 1. Re: how can i perform operations on a string written as an algebraic expression
          800282
          epoy wrote:
          i need help...how can i have a program that a string like this ---"1 + 2 + 3"---could be read as integers and you can actually come to a single result using the precedence of operations...
          That's not as easy as it sounds.

          If you only have fairly simple mathematical expressions have a look at:
          - if you have JDK 1.6, see reply #7 [http://forums.sun.com/thread.jspa?threadID=5144807]
          - or if you have JDK 1.5 (or less), have a look at reply #12 from the same thread.

          If you need more fancy math functions, Google for "JEP", or "mathematical expression parser".

          Good luck.