There are issues with the code but the culprit is most likely this line:
double square = Math.sqrt(b*b - 4*a*c);
If b*b - 4*a*c
is negative (there is no solution to the equation) then square is NaN and every computation involving it will be NaN as well. You can check it here.
You could improve your calculator by first checking if b*b - 4*a*c < 0
and if it is so then you could write to the console that there is no real solution (and of course stop the computations there).
I would change public void algorithm(int a, int b, int c)
to
public void algorithm(double a, double b, double c)
Integer arithmetic can surprise you when you least expect it and I see no reason why a
, b
and c
should be constrained to be int
-s.
OK, hope this helped.