Ask your own question, for FREE!
Computer Science 15 Online
OpenStudy (anonymous):

in java write program that add two Polynomials but the user will enter Polynomials as string

OpenStudy (konradzuse):

have you started any of this yourserlf?

OpenStudy (anonymous):

i solved it without string

OpenStudy (anonymous):

can u write the code pls ?

OpenStudy (anonymous):

u can help !!

OpenStudy (konradzuse):

okay so you want an integer lets say.

OpenStudy (konradzuse):

there is something calling parsing. For an integer you would do Integer.parseInt(String);

OpenStudy (konradzuse):

but a polynomial like a math function? x^2 + 3x + 10?

OpenStudy (anonymous):

the user will enter like that enter first polynomial :x^2+x+1 enter first polynomial :5x^5+x^3+3x^2+10 the result is:5x^5+x^3+4x^2+11

OpenStudy (konradzuse):

Well you could do something that looks for a character sequence and adds them ie "x^5"

OpenStudy (anonymous):

if u can ,write the code pls send it pls

OpenStudy (anonymous):

This isn't the right place to ask for someone to do your homework for you. Anyway, if you know this exact format is being used, you can parse all numbers before an x as the coefficient and the number after the ^ as the exponent. When it comes to storing polynomials, there are a few methods that work well. If the exponents are sparse, store polynomials as a pair of coefficient and exponent instead of a list of the coefficient for each exponent. If there are multiple unknowns, a custom data structure may be necessary, depending on the number of values and whether multiple variables may be bundled together. If the roots of the polynomial are being found, they need to be stored as complex numbers for the deflation process. If the polynomial requires simplification, the data structure needs to be sortable.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!