共计 278 个字符,预计需要花费 1 分钟才能阅读完成。
须要给 double 类型的数据开根号
要求精度在 0.0001 之内
public double getSqrtNum(double num){
double left;
double right;
double mid;
if(n<1&&n>0){
left = num;
right = 1;
}
if(n>1){
left = 0;
right = num;
}
mid = (left+right)/2;
while(Math.abs(mid*mid-n)>0.0001){if(mid*mid<n){left = mid;}else{right = mid;}
mid = (left+right)/2;
}
return mid;
}
正文完