【发布时间】:2012-04-01 23:24:25
【问题描述】:
我正在对一个计算二次方程结果的程序进行代码测试
我需要有以下情况的测试数据,当 a 不为零且 d 为正时,下面的代码中有两种可能性,我需要在 Math.abs(b / a - 200.0)
caption= "Two roots";
if (Math.abs(b / a - 200.0) < 1.0e-4)
{
System.out.println("first one");
x1 = (-100.0 * (1.0 + Math.sqrt(1.0 - 1.0 / (10000.0 * a))));
x2 = (-100.0 * (1.0 - Math.sqrt(1.0 - 1.0 / (10000.0 * a))));
}
else
{
System.out.println("secrst one");
x1 = (-b - Math.sqrt(d)) / (2.0 * a);
x2 = (-b + Math.sqrt(d)) / (2.0 * a);
}
}
}
【问题讨论】: