我希望 Quadratic 程序只打印必要的输出。这是代码:
public static void main(String[] args) {
double a = Double.parseDouble(args[0]);
double b = Double.parseDouble(args[1]);
double c = Double.parseDouble(args[2]);
double temp, first, second;
temp = (b*b - (4 * a * c));
first = ((-1 * b) + Math.sqrt(temp)) / (2 * a);
second = ((-1 * b) - Math.sqrt(temp)) / (2 * a);
if (temp > 0)
System.out.println (first);
if (temp == 0)
if (first == second)
System.out.println (first);
else
System.out.println (first);
System.out.println (second);
if (temp < 0)
System.out.println ("There are no solutions.");
}
当我在写:java Quadratic 1 0 1 时,它带回:“NaN 没有解决方案。” 什么是 NaN?
当我写:java Quadratic 1 -2 1 它打印两次:“1.0 1.0”。我如何变成一个人?因为我已经写了这个 if 命令:if (first == second)。
太感谢了!!!