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"); } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter