Run Code  | API  | Code Wall  | Misc  | Feedback  | Login  | Theme  | Privacy  | Patreon 

Quadratic equation

//'main' method must be in a class 'Rextester'.
//Compiler version 1.8.0_111

import java.util.*;
import java.lang.*;

class Rextester
{  
    public static void main(String args[])
    {
    Scanner sc=new Scanner(System.in);
    double a,b,c,x,y;
    System.out.println("Enter the three coefficients");
    a=sc.nextDouble();
    b=sc.nextDouble();
    c=sc.nextDouble();
    x=(-b+Math.sqrt(b*b-4*a*c))/(2*a);
    y=(-b-Math.sqrt(b*b-4*a*c))/(2*a);
    System.out.println("roots are"+x+"and"+y);
    }
}
 run  | edit  | history  | help 0