3
I created a class with two properties as in the example below:
class Polinomio {
private int coeficientes;
private int expoente;
}
I will create a list to receive a polynomial type where I will receive the terms for performing the sum, subtraction and multiplication operations.
List<Polinomio> lst = new ArrayList<Polinomio>();
When I pass one string like any of these below in the builder would like to break the terms, but I’m not getting.
- a) -4x 5 + 3x 2 + 4
- b) -4x 3 + 3x 2 - 8
- c) 3x 3 - 3x 2 + 4
- d) 3x 3 - 3x 2 + 2
When it broke would be.
- a) lst = p1(-4,5),p2(3,2),p3(4,0)
- b) lst = p1(-4,3),p2(3,2),p3(-8,0)
- c) lst = p1(3,3),p2(-3,2),p3(4,0)
- d) lst = p1(3,3),p2(-3,2),p4(4,0)
P1,P2,P3.. are the positions the elements will be in the list. In the case of the last term when it is only 1 number without "x" it writes as zero. By default the polynomials will have the same variable "x".
How can I break the terms?
Related: "Equation solving" (a little more general, maybe Overkill for your case, but I’m mentioning case you find useful)
– mgibsonbr