Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
778 B
1
Indexable
Never
import java.util.*;

class Quadratic

{
public static vod main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the a,b,c values");
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
double d=(b*b)-(4*a*c);
double root1,root2;
if(d==0)
{
System.out.println("roots are real and equal");
root1=root2=-b/(2*a);
System.out.println("root1="+root1+"root2="+root2);
}
else if(d>0)
{
System.out.println("roots are real and unequal");
root1=(-b+Math.sqrt(d))/(2*a);
root2=(-b-Math.sqrt(d))/(2*a);
System.out.println("root1="+root1+"root2="+root2);
}
else
{
System.out.println("roots are imaginary");
}
}
}
output:
javac Quadratic_Equation.java
java Quadratic_Equation 1 2 1
First root is:-1.0
Second root is:-1.0
Leave a Comment