I'm reading a Introductory programming book by Robert Sedgewick and Kevin Wayne.
In one of the examples they implement a quadratic class as follows:
public class Quadratic
{
public static void main(String[] args)
{
double b = Double.parseDouble(args[0]);
double c = Double.parseDouble(args[1]);
double discriminant = b * b - 4.0 * c;
double d = Math.sqrt(discriminant);
System.out.println((-b + d) / 2.0);
System.out.println((-b - d) / 2.0);
}
}
The author omits the 'a' coefficient of the quadratic formula. Is this because the 'a' coefficient can be cancelled out (numerator / denominator)?
Based on the feedback… Would the following be the correct solution:
public static void main(String[] args)
{
double b = Double.parseDouble(args[0]);
double c = Double.parseDouble(args[1]);
double a = Double.parseDouble(args[2]);
double discriminant = b * b - 4.0 * a * c;
double d = Math.sqrt(discriminant);
System.out.println((-b + d) / (2.0 * a));
System.out.println((-b - d) / (2.0 * a));
}