import java.util.Scanner;
//ax^2+bx+c=0 求根
public class TestTwo {
public static void main(String[] args) {
double a,b,c;
Scanner sc=new Scanner(System.in);
System.out.println("输入a,b,c三个数:");
System.out.print("输入数a:");
a=sc.nextDouble();
System.out.print("输入数b:");
b=sc.nextDouble();
System.out.print("输入数c:");
c=sc.nextDouble();
qiuRoot(a, b, c);
}
static void qiuRoot(double a,double b,double c) {
double x1=0,x2=0;
double realpart=0, imagepart=0;
double disc=0;
//if(a!=0)
//float f1=3.0f; //3.00000000003214343214
//float f2=3.0f;//3.0000000000006453646543
if(Math.abs(a)<1e-6) { //说明a=0
System.out.println("这不是一个一元二次方程");
System.exit(0);
}else {
System.out.println("一元二次方程");
disc=b*b-4*a*c;
}
if(Math.abs(disc)<1e-6) {
System.out.println("有两个相等的根:"+(-b/(2*a)));
}else if (Math.abs(disc)>=1e-6) {
x1=(-b+Math.sqrt(disc))/(2*a);
x2=(-b-Math.sqrt(disc))/(2*a);
System.out.println("有两个不相等的根:"+"x1="+x1+" x2="+x2);
}else {