## Write a java program that prints all real solutions to the quadratic equation

Write a java program that prints all real solutions to the quadratic equation ax2+bx+c=0. Read in a,b,c and use the quadratic formula. If the discriminant b2-4ac is negative, display a message stating that there are no real solutions.

The program for find all the real solution to a quadratic equation contains the following steps
• Find the discriminant d using the formula b*b-4*a*c
• Find the roots base on discriminant
``````
import java.util.*;
{
public static void main(String args[])
{
int a,b,c,d;
double e,f;
System.out.println("Enter a,b,c values");
Scanner sc = new Scanner(System.in);
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
System.out.println("Enterd values are a="+a+" b="+b+" c="+c);
d=(b*b)-(4*a*c);
if(d<0)
{
System.out.println("No real roots");
}else
{
e=((-b+Math.sqrt(d))/(2*a));
f=((-b-Math.sqrt(d))/(2*a));
System.out.println("Roots are "+e+" "+f);
}
}
}
``````

Name

Email *

Message *

More

More

More

More

More

More