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); } }
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