public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
double a,b,c,x1,x2,bb,fourac,twoa,tmp,tmp1;
int n;
String str = sc.nextLine();
n = Integer.parseInt(str);
for(int i=0;i<n;i++) {
str = sc.nextLine();
String[] split = str.split(" ");
a = Double.parseDouble(split[0]);
b = Double.parseDouble(split[1]);
c = Double.parseDouble(split[2]);
bb=b*b;
fourac=4*a*c;
twoa=-b/(a*2);
if(b==0)
twoa=0;
if(bb==fourac)
System.out.printf("x1=x2=%.5f\n" , twoa);
else if(bb>fourac)
{
tmp=Math.sqrt(b*b-4*a*c);
tmp1=2*a;
x1=(-b+tmp)/tmp1;
x2=(-b-tmp)/tmp1;
System.out.printf("x1=%.5f;x2=%.5f\n" , x1 , x2);
}
else
System.out.printf("x1=%.5f+%.5fi;x2=%.5f-%.5fi\n" ,twoa,(Math.sqrt(fourac-bb)/(a*2)),twoa,(Math.sqrt(fourac-bb)/(a*2)));
}
}
}
POJ 一元二次方程的根
最新推荐文章于 2024-06-02 13:47:41 发布