0

I'm making a program where I need to parse equations like 2*xˆ2+Ax+1=R (max exponent of x is 10). Also, R is a constant so I can only parse string without it. I'm trying to parse each bx^n into a separate class:

class Equation{
    int coefficient;
    int exponent;
}

And then put all Equations into an ArrayList. To get exponent of x, I'm doing:

    if (string.charAt(i) == 'x' && string.charAt(i + 1) == '^') {
        if (string.charAt(i + 3) == '0') {
            pomocna.potencija = 10;
        }
        else
            pomocna.potencija = Character.getNumericValue(string.charAt(i + 2));
    }
    if (string.charAt(i) == 'x' && string.charAt(i + 1) == '+'){
        pomocna.potencija = 1;
    }

as exponent can be 1 (then it's not written), 2-9 and 10.

However, what I can't seem to do is to get b, in b*x^n, as b can also be a decimal number.

How can I find b by each x? Thank you.

leonz
  • 1,107
  • 2
  • 10
  • 32

0 Answers0