import java.util.*;
class quadFormula
{
static Scanner input = new Scanner(System.in); // Quadratic Formula
public static void main(String[] args)
{
String contYorN = "Y";
while (contYorN.equalsIgnoreCase("y"))
{
System.out.println("This program will calculate the roots for a quadratic equation");
System.out.print("Please input the constants in the following order(without the commas)' a, b, c ' .\nUse the following as a reference : ax^2 +bx+c = 0");
System.out.print(":");
double a = input.nextDouble();
double b = input.nextDouble();
double c = input.nextDouble();
double discrim = Math.pow(b,2)-(4*a*c);
if (discrim < 0)
{
System.out.println("There are not any real roots");
System.exit(0);
}
else
{
double rt1 =(int)((-b + Math.pow(discrim,.5))*1000)/(1000.0*2*a); // root 1
double rt2 =(int)((-b - Math.pow(discrim,.5))*1000)/(1000.0*2*a); // root 2
System.out.println("The real roots are " +rt1 + " " +rt2);
}
System.out.print("\nWould you like to use this program again? Please type 'y' or 'n' : ");
contYorN = input.nextLine();// Trying to make this program loop.
}
}
}