import java.util.Scanner; public class Quadratic4 { public static void main (String[] Args) { System.out.println("Solving quadratic equations Ax^2 + Bx + C"); System.out.println("Enter real numbers A, B, C"); Scanner getInput = new Scanner(System.in); double A = getInput.nextDouble(); double B = getInput.nextDouble(); double C = getInput.nextDouble(); double discriminant = B*B - 4.0*A*C; double ans; if (A == 0) { System.out.println("A linear equation; only one root"); ans = -C/B; System.out.println("The one root is " + ans); } else if (discriminant < 0) { System.out.println("No (real) roots"); } else if (discriminant == 0) { System.out.println("One (double) root"); ans = -B/(2*A); System.out.println("The double root is/are " + ans); } else { // discriminant > 0 double ans1 = (-B + Math.pow(discriminant,0.5))/(2.0*A); double ans2 = (-B - Math.pow(discriminant,0.5))/(2.0*A); System.out.println("The roots are " + ans1 + " and " + ans2); } } } // Local Variables: // compile-command: "javac Quadratic4.java" // c-basic-offset: 2 // End: