how to compute a string of arithmetic expression?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: how to compute a string of arithmetic expression?

  1. #1
    Join Date
    May 2004
    Posts
    12

    how to compute a string of arithmetic expression?

    a string of arithmetic expression is given, ask to calculate the result, for example:

    2+3*3

    this is what the user input, the program should calculate the result , may i know how to do this? thx a lot

  2. #2
    Join Date
    Feb 2004
    Posts
    808
    that string is in what is called INFIX format.. it will be easier to calculate if it were in POSTFIX format.. try this website for an idea about postfix:
    http://www.spsu.edu/cs/faculty/bbrow...tures/postfix/

    this thread also discusses post fix, somewhat:

    http://www.codeguru.com/forum/showth...=migrate+right

    you may also choose (instead) to adopt a scanna nd reduce approach, first scanning the entire string for * operators, and multiplying their operands, then scan for / divides and div the operands, etc..

    in 4 method calls you should have a single answer..

    make your methods somethign like:

    public string reduceMultipliers(String input){}

    the method should take a string such as 1+2*3, and return the string: "1+6"

    ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center