I tried and succeed to build a quadratic equation solver.
public class Solver {
public static void main (String[] args) {
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
int c = Integer.parseInt(args[2]);
double positive = (-b + Math.sqrt(b*b-4*a*c))/2*a;
double negative = (-b - Math.sqrt(b*b-4*a*c))/2*a;
System.out.println("First answer is " + positive);
System.out.println("Second answer is " + negative);
}
}
Sometimes I get NaN in the output. What did i do wrong?