Question: Hello, I'm having trouble with this certain part to a project of mine. Say I have two strings, String left and String right. This is

Hello, I'm having trouble with this certain part to a project of mine. Say I have two strings, String left and String right. This is part of an expression evaluation problem, and I need to have a certain piece of the expression in left and a certain piece of the expession in right. The code I have works with everything except if * or / come before + or -. No parentheses included, I have another method that deals with that. Say I have 2+3*3, using my code yoy get 11 which is correct. But if you have 3*3+2, it gives 15 (adding before multiplying). I know why it doesn't work, but I can't seem to fix it, I always end up with a stringoutofbounds exception.

So for example: 2+3*3 String left = 2 String right = 3*3 operation = +

Another example: 8*4-2 String left = 8*4 String right = 2 operation = -

Any help would be greatly apprecited

Hello, I'm having trouble with this certain part to a project of

EDIT: I solved this myself, thanks anyway if anyone was going to help.

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 string left String right char operator float result No parentheses or arrays in mind s. length i++) for int i if (i+1 s length l I i+2 s.length()) f break if (s char t (i-1) l I s charAt (i+1) left s. substring (0, i+1); right s substring (i+2, s. length operator s.charAt (i+1); break else if (s.charAt(i+1) I I S. Char (i+1) left s substring (0, i+1 right s. substring it s length s.charAt it operator break

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!