write java program that display the roota of a quadratic equation ax2+bx=0
Answers
Answered by
1
Answer:
Program:-
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int a,b,c;
double x1=0,x2=0;
System.out.println("Enter a:");
a=in.nextInt();
System.out.println("Enter b:");
b=in.nextInt();
System.out.println("Enter c:");
c=in.nextInt();
if(b*b-4*a*c>=0)
{
x1=((-b)+(Math.sqrt(b*b-4*a*c)))/2.0;
x2=((-b)-(Math.sqrt(b*b-4*a*c)))/2.0;
System.out.println("The roots are possible:");
System.out.println("The first root="+x1);
System.out.println("The second root="+x2);
}
else
System.out.println("The roots are imaginary");
in.close();
}
}
- The first root is like this
It is possible and has solution -2,-3
(x+2)=0 or (x+3=0)
- The second root is not possible
Which is not possible so it gave the roots are imaginary.
- The third root is also possible and the roots are equal.
More information:-
Quadratic equation formula:-
Attachments:
Similar questions