import java.util.Scanner; public class Quadratic4 { public static void main (String[] args) { // The next line is for hardwiring; we are reading the count // final int count = 10; Scanner getInput = new Scanner(System.in); System.out.println("Solving quadratic equations ax^2 + bx + c"); System.out.println("How many equations are to be solved?"); int count = getInput.nextInt(); while (count-- > 0) { System.out.println("Enter real numbers a, b, c"); double a = getInput.nextDouble(); double b = getInput.nextDouble(); double c = getInput.nextDouble(); if (a == 0) if (b != 0) System.out.println("One real root: " + -c/b); else if (c == 0) // note a and b are zero System.out.println("Trivial: all values are roots!"); else System.out.println("Inconsistant: no roots!"); else { // a != 0 double discriminant = b*b - 4.0*a*c; if (discriminant < 0) System.out.println("The roots are complex"); else if (discriminant == 0) System.out.println("One (double) root: " + -b/(2*a)); 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("Two roots: " + ans1 + " and " + ans2); } } } } }