Roots of Quadratic equations

PHOTO EMBED

Tue Dec 26 2023 06:47:06 GMT+0000 (Coordinated Universal Time)

Saved by @python

import java.util.Scanner;
public class RootsOfDemo {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        double det,root1,root2;

        System.out.println("ENTER THE VALUES OF a,b,and c :");

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        det = (b*b)- 4*a*c;

        if(det>0){
            System.out.println("Roots are Real and Distinct ");
            root1 = (-b) + Math.sqrt(det)/(2*a);
            root2 = (-b) - Math.sqrt(det)/(2*a);
            System.out.println("The Roots are : "+ root1 + root2);
        }

        else if(det==0){
            System.out.println("Roots are Real and Equal ");
            root1 = -b/2*a;
            System.out.println("The Roots are : "+ root1 + root1);
        }

        else{
            System.out.println("Roots are Imaginary ");
            double img = Math.sqrt(det*-1)/2*a;
            //System.out.println("The real part is "+ -b/2*a +" The imaginary part is "+ ( Math.sqrt(det*-1)/2*a ) +"i" );
            System.out.println("The img roots are "+ -b/2*a +"+"+ img + "i");
            System.out.println("The img roots are "+ -b/2*a +"-"+ img + "i");
        }


    }
    
}
content_copyCOPY