Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

Students also viewed these Databases questions