Java 用巴比伦算法计算平方根
对于我的作业,我应该使用“容忍标志”。然而,到目前为止,我已经能够完成这项任务。我的老师所说的宽容标志是什么意思Java 用巴比伦算法计算平方根,java,Java,对于我的作业,我应该使用“容忍标志”。然而,到目前为止,我已经能够完成这项任务。我的老师所说的宽容标志是什么意思 Use a tolerance flag and make your variables a member of the double class. const double TOLERANCE = 5e-8; double x = 2.0; _ 我的工作: public class Sqrt_of_Two { public static void main(String
Use a tolerance flag and make your variables a member of the double class.
const double TOLERANCE = 5e-8;
double x = 2.0;
_
我的工作:
public class Sqrt_of_Two {
public static void main(String[] args) {
final double TOLERANCE = 5e-8;
double x = 2;
do{
x = (x + 2/x) / 2;
System.out.println(x);
}while( Math.ceil(x*x) > 2);
}
}
输出:
1.5
1.4166666666666665
1.4142156862745097
1.4142135623746899
1.414213562373095
我想它的意思是:
while(Math.abs(x*x - 2) > TOLERANCE);
哪些产出:
1.5
1.4166666666666665
1.4142156862745097
1.4142135623746899
我想它的意思是:
while(Math.abs(x*x - 2) > TOLERANCE);
哪些产出:
1.5
1.4166666666666665
1.4142156862745097
1.4142135623746899
@这是一个在线作业。我还没有得到答复。@SotiriosDelimanolis这是一个在线作业。我还没有得到答复。