Results 1 to 5 of 5
  1. #1
    a_aagain is offline Member
    Join Date
    Apr 2009
    Posts
    1
    Rep Power
    0

    Unhappy Help! URGENT.. i need to be able to evaluate PEMDAS expressions using stacks..

    i need to use java for this.. i must evaluate a PEMDAS expression using stacks..

    The ff are valid expressions:

    1. (40 + 5 * 2^2)*10+2 Ans: 602
    2. 2^-2+1 and 2^(-2)+1 Ans: 1.25
    3. 4 + 5 * 3 + -1 and 4 + 5 * 3 + (-1) Ans: 18
    4. 2^2^3*10 and 2^(2^3)*10 Ans: 2560 *Exponentiation is
    right-associative
    5. (2^2)^3*10 Ans: 640
    6. -4 + 2 - -8 * -3 and (-4) + 2 - (-8) * (-3) Ans: -18
    7. 5 / -1 * (6 + 1) and (5) / (-1) * (6 + 1) Ans: -35
    8. 10 - 5 - 2 - 1 and (((10-5)-2)-1) Ans: 2
    *Subtraction is
    left-associative
    9. 3 / 3 / 3 * 100 and ((3 / 3) / 3) * 100) Ans: 33.33
    *Division is left-associative
    10. 5 - 3 * +2 Ans: -1

    while the ff are invalid:

    1. 5 + 3 % 2
    2. (9 * 6 + 8)^2)
    3. 5 +^ 3
    4. 5 ^/ 3
    5. 5 + ( * 4
    6. a + 5
    7. (5-7)(68)
    8. 3 - 5 +

    please can anyone help me..? i badly need it.. a lot is at stake if i won't be able to do this..

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    a lot is at stake if i won't be able to do this..
    But you evidently can't do this. The fact the millions of others can - including some reading this forum - does not in the least change the fact that you cannot.

    If you find this state of affairs unpalatable, change it. Read your textbooks and notes and write some code. You may surprise yourself and be able to do the work that was assigned to you. But if not, you will at least have a question (possibly more) to ask.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  4. #4
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    so, what is your problem?

    Java Code:
    (40 + 5 * 2^2)*10+2 Ans: 602  is valid
    5 + 3 % 2  is invalid
    correct
    Last edited by mtyoung; 04-01-2009 at 11:28 AM.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    I think he's looking at how the stack behave in Java. That's why I said, he should looking how the stack implemented, basically how it constructed. Anyway, we need more details about the question.

Similar Threads

  1. any can help me? About MDAS and PEMDAS rules.
    By darlineth in forum New To Java
    Replies: 12
    Last Post: 09-07-2008, 02:21 PM
  2. Stacks, lists...
    By little_polarbear in forum New To Java
    Replies: 7
    Last Post: 08-02-2008, 01:59 PM
  3. calculator java following pemdas rule
    By sassygirl_kea9@yahoo.com in forum New To Java
    Replies: 2
    Last Post: 07-10-2008, 04:15 AM
  4. Stacks
    By Zosden in forum Advanced Java
    Replies: 15
    Last Post: 05-05-2008, 08:16 AM
  5. Using Stacks
    By ravian in forum New To Java
    Replies: 7
    Last Post: 11-28-2007, 09:53 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
  •