// Arup Guha
// 7/14/05
// This program asks the user for a, b, and c from the quadratic equation,
// and then solves the equation for real roots. If the equation has complex
// roots, then a message stating so is printed to the screen.

import java.util.*;

public class Quadratic {


  public static void main(String[] args) {

    Scanner stdin = new Scanner(System.in);
 
    double a, b, c;

    // Get the input from the user.
    System.out.println("Enter a from your quadratic equation.");
    a = stdin.nextDouble();
    System.out.println("Enter b from your quadratic equation.");
    b = stdin.nextDouble();
    System.out.println("Enter c from your quadratic equation.");
    c = stdin.nextDouble();

    // Calculate the discriminant.
    double discriminant = Math.pow(b,2) - 4*a*c;

    // Complex root case.
    if (discriminant < 0) {
      // Calculate the real part of the root.
      double real = -b/(2*a);

      // Calculate the imaginary part of the root.
      double imaginary = Math.sqrt(Math.abs(discriminant))/(2*a);
      System.out.println("First root = "+real+" + "+ imaginary +"i.");
      System.out.println("Second root = "+real+" - "+ imaginary +"i.");
    }
    // Real root case.
    else {

      double r1 = (-b + Math.sqrt(discriminant))/(2*a);
      double r2 = (-b - Math.sqrt(discriminant))/(2*a);
     
      System.out.println("The roots to your quadratic are " + r1 + " and " + r2 + ".");
    }

  }

}
