Results 1 to 5 of 5
- 04-01-2009, 07:58 AM #1
Member
- Join Date
- Apr 2009
- Posts
- 1
- Rep Power
- 0
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..
- 04-01-2009, 08:33 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
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.a lot is at stake if i won't be able to do this..
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.
- 04-01-2009, 08:40 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
First of all you should looking into stack implementation.
- 04-01-2009, 10:27 AM #4
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
so, what is your problem?
correctJava Code:(40 + 5 * 2^2)*10+2 Ans: 602 is valid 5 + 3 % 2 is invalid
Last edited by mtyoung; 04-01-2009 at 11:28 AM.
- 04-01-2009, 12:25 PM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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
-
any can help me? About MDAS and PEMDAS rules.
By darlineth in forum New To JavaReplies: 12Last Post: 09-07-2008, 02:21 PM -
Stacks, lists...
By little_polarbear in forum New To JavaReplies: 7Last Post: 08-02-2008, 01:59 PM -
calculator java following pemdas rule
By sassygirl_kea9@yahoo.com in forum New To JavaReplies: 2Last Post: 07-10-2008, 04:15 AM -
Stacks
By Zosden in forum Advanced JavaReplies: 15Last Post: 05-05-2008, 08:16 AM -
Using Stacks
By ravian in forum New To JavaReplies: 7Last Post: 11-28-2007, 09:53 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks