package quadraticequation;
import java.util.Scanner;
public class QuadraticEquation {
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter the value of a\n");
double a_coff = scan.nextDouble();
System.out.println("Enter the value of b\n");
double b_coff = scan.nextDouble();
System.out.println("Enter the value of c\n");
double c_coff = scan.nextDouble();
double root1, root2;
double determinant = b_coff * b_coff - 4 * a_coff * c_coff;
if (determinant > 0) {
root1 = (-b_coff + Math.sqrt(determinant)) / (2 * a_coff);
root2= (-b_coff - Math.sqrt(determinant)) / (2 * a_coff);
}
else if (determinant == 0) {
root1 = root2 = -b_coff / (2 * a_coff);
}
else {
root1 = -b_coff / (2 * a_coff);
root2 = Math.sqrt(-determinant) / (2 * a_coff);
}
System.out.println("Root 1: "+root1+"\nRoot 2: "+root2);
}
}
Comments
Leave a comment