qudratic roots
Thu Jan 18 2024 18:12:28 GMT+0000 (Coordinated Universal Time)
Saved by
@login
import java.util.Scanner;
public class RootsType{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
float det;
double root1,root2;
System.out.println("enter the number a,b,c");
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
det = b*b-4*a*c;
root1 = (- b + Math.sqrt(det))/2*a;
root2 = (- b - Math.sqrt(det))/2*a;
if(det==0)
System.out.println("Roots are real and equal");
else if(det>0)
System.out.println("roots are real and distinct");
else
System.out.println("roots are imaginary");
System.out.println("root1:"+root1);
System.out.println("root2:"+root2);
}
}
content_copyCOPY
Comments