/* Using IO streams instead of programmer defined Keyboard class * * Determines the roots of a quadratic equation. */ import java.io.*; class Quadratic1 { public static void main (String[] args) throws IOException { InputStreamReader s = new InputStreamReader(System.in); BufferedReader t = new BufferedReader(s); int a, b, c; // ax^2 + bx + c String str1, str2, str3; System.out.print ("Enter the coefficient of x squared: "); str1 = t.readLine(); a = Integer.parseInt(str1); System.out.print ("Enter the coefficient of x: "); str2 = t.readLine(); b = Integer.parseInt(str2); System.out.print ("Enter the constant: "); str3 = t.readLine(); c = Integer.parseInt(str3); // Use the quadratic formula to compute the roots. // Assumes a positive discriminant. double discriminant = Math.pow(b, 2) - (4 * a * c); double root1 = ((-1 * b) + Math.sqrt(discriminant)) / (2 * a); double root2 = ((-1 * b) - Math.sqrt(discriminant)) / (2 * a); System.out.println ("Root #1: " + root1); System.out.println ("Root #2: " + root2); } }