Mental block on this assignment


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Mental block on this assignment

  1. #1
    Join Date
    Jan 2007
    Posts
    1

    Mental block on this assignment

    Write a program in Java that takes as input a mathematical expression consisting of decimal numbers and the four basic mathematical operators (addition, subtraction, multiplication and division) and nested mathematical expressions, and evaluates this expression.

    Some examples:
    5 + 6 * 2
    (5 + 4) * (4 - 2)
    (4 + (2 * (2 - 1))) * 1.2

    Any ideas as to how I could go about this? Any general algorithms would be good. I think you have to use a composite design pattern?

    Cheers

  2. #2
    Join Date
    Jan 2007
    Posts
    3
    you need to convert the expression from infix to postfix and then use a stack to evaluate it. There are several examples on how to do this on the web.

  3. #3
    Join Date
    May 2005
    Location
    Ontario, Canada
    Posts
    173
    Quote Originally Posted by celerity66
    you need to convert the expression from infix to postfix and then use a stack to evaluate it. There are several examples on how to do this on the web.
    Do you mean INORDER to POSTORDER or there is infix and postfix as well?

  4. #4
    Join Date
    Jan 2007
    Posts
    3
    Right... Inorder to postorder. Here is a link: Math Expression Evaluation

Similar Threads

  1. Replies: 1
    Last Post: 10-05-2006, 05:07 PM
  2. Multiple Catch Block for a single Try Block
    By software_develo in forum .NET
    Replies: 3
    Last Post: 08-15-2006, 11:26 AM
  3. Replies: 3
    Last Post: 10-21-2005, 10:06 AM
  4. Remoting With Caching Block
    By balamemory in forum .NET
    Replies: 0
    Last Post: 03-05-2005, 04:16 AM
  5. GOSUB vs. Macros vs. Nested Functions
    By Jonathan Allen in forum .NET
    Replies: 331
    Last Post: 03-19-2001, 08:00 AM

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