python題求解輸入a?
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 {