import java.util.Scanner; public class Quadratic5 { public static void main (String[] Args) { System.out.println("Solving quadratic equations ax^2 + bx + c = 0"); 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) { if (b==0) { if (c==0) { System.out.println("Silly equation; all values are roots"); } else { System.out.println("Degenerate equation; no roots"); } } else { 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(s) 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 Quadratic5.java" // c-basic-offset: 2 // End: