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

JNTUK JAVA LAB PROGRAMS :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.

 ANS:--


import java.lang.*;
import java.util.*;
class Quadratic
{
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 br="br">{
  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);
}
}
}
 


Post a Comment

Please Select Embedded Mode To Show The Comment System.*

Previous Post Next Post