Spilled coefficients from quadratic equation into JAVA bugs
I am trying to spill coefficients from a quadratic equation and I got the function, but there is no output when I run this program. if the input string
String eqn = "4x2-3x+45=0";
equatin = quad(eqn);
equatin="Answer = "+equatin;
the quad function above is called. A square function will split the coefficients into a quadratic equation. eg data input "4x2-3x + 45 = 0" AND the required output is 4 -3 45
public static String quad (final String equation)
{
int a1 ;
int b1 ;
int c1 ;
final String regex = "([+-]?\\d+)[xX]2([+-]\\d+)[xX]([+-]\\d+)=0";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(equation);
if (matcher.matches()) {
a1= Integer.parseInt(matcher.group(1));
b1 = Integer.parseInt(matcher.group(2));
c1 = Integer.parseInt(matcher.group(3));
String st6 ,st7,st8,st9;
st7 = String.valueOf(a1);
st8 = String.valueOf(b1);
st9 = String.valueOf(c1);
st6=st7+""+st8+""+st9;
return st6;
} else { /* throw exception or return null */
String st5 = "wrong";
return st5;
}
}
+3
source to share
No one has answered this question yet
Check out similar questions: