1. 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 roots .
import java.util.Scanner;
class Solutions
{
public static void main(String args[])
{
int a,b,c;
double x,y;
Scanner s=new Scanner(System.in);
System.out.println("Enter the values of a,b, and c");
a=s.nextInt();
b=s.nextInt();
c=s.nextInt();
double f=(b*b)-4*a*c;
System.out.println("F value="+f);
if(f<0)
{
System.out.println("No real roots");
}
else
{
double l=Math.sqrt(f);
System.out.println("Math.sqrt(f)="+l);
x=((-b-l)/(2*a));
y=((-b+l)/(2*a));
System.out.println("Roots of given equation:"+x+"\t"+y);
}
}
}
Output:
Enter...