0
Trouble with Java program for solving Quadratic Formula
When I run the program I get an issue where the roots come out as Na and do not give me an answer and I am having trouble figuring it out. https://code.sololearn.com/cPniQ1yT2anr/?ref=app
3 Respostas
+ 1
What input you are giving..?
If Math.sqrt( negetive numbers) return NaN.
So take b*b - 4ac absolute value..
root1 = - b + Math.sqrt(Math.abs((b*b)-(4*a*c)));
[But I think result may differ. Check ones...]
0
Jayakrishna🇮🇳 I have been using positive numbers as my input, I haven't tried any negative numbers yet
0
Angel Armndariz
I mean result of b*b - 4*a*c
Ex: 5 4 3
Now 4 * 4 - 4*5*3 =16-60= -46
Math.sqrt( -46) is NaN.
But chech input 2 5 2
Result you get 5*5 - 4*2*2 =25-16=9
Math.sqrt(9) =3
Check for these two cases..... You can understand.