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: