Math.sqrt 在尝试求解二次方程时在 eclipse 中显示无法解释的错误

Math.sqrt showing an unexplained error in eclipse when trying to solve a second degree equation

我正在尝试创建一个求解二次方程的程序 (ax 2 + bx + c = 0) .当我删除 Math.sqrt(delta) 时它工作正常,但拥有它是过程中非常重要的部分,我无法弄清楚为什么它不起作用。

当我 运行 程序时,它在最后给了我 X1 = Nan X2 = Nan

public static void main(String[] args) {
    double a, b, c, x1, delta;
    
    Scanner sc = new Scanner(System.in);
    System.out.println("Entrez Les Valeurs De a, b et c: ");
    a = sc.nextInt();
    b = sc.nextInt();
    c = sc.nextInt();
    
    delta = (b * b) - 4 * ( a * c );


    x1 = (-b + Math.sqrt( delta ) )/(2 * a);
    
    
    System.out.println("X1= " + x1);
                    
    
}

如果 delta 结果为负,sqrt 将 return NaN