求一元二次方程的2个跟

/*
 * 
 * 需求:
 * 求一元二次方程的2个跟
 * 
 * 
 */
public class Demo {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入a,b,c的值:");
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = (int) (Math.pow(b, 2)-4*a*c);
        if(d>0){
            double r1 =(int) ((-b+Math.pow(d, 0.5))/(2*a)*100)/100.0;
            double r2 = (int)((-b-Math.pow(d, 0.5))/(2*a)*100)/100.0;
            //double r3 = (r1*100)/100.0;
            System.out.println("结果是"+r1+"和"+r2);
        }else{
            System.out.println("方程没有实根");
        }
    }
}
原文地址:https://www.cnblogs.com/flei/p/6657063.html