我正在研究java eclipse mars中二次公式的函数,当我编译代码时,它输出NaN,在数学上这个答案是可能的,我应该得到2.0请帮助
import java.util.Scanner;
public class Quadradic1 {
public static void main(String[] args) {
double a;
double b;
double c;
double x;
System.out.print("Input A B C: ");
Scanner input = new Scanner(System.in);
a = input.nextDouble();
b = input.nextDouble();
c = input.nextDouble();
x = (-b + Math.sqrt(b * b + 4 * a * c))/(2 * a);
System.out.println("Quadratic1 " + x);
}
}
很抱歉,我输入的值是a = 1 b = 2和c = -8
答案 0 :(得分:0)
供您参考
mdpi
评估为b * b + 4 * a * c
。没有负数的平方根