java用级数求双精度的平方根
问题是:
Using the following approximate formula, write a function or method that returns the square root of a real number! Use the sequence x[k + 1] = 1/2 * (x[k] + a / x[k]), which is converges to a square root of 'a' real parameter if x1 = 1.
我的解决方案与此类似,但没有使用以下公式:
public static double squareRoot(double a) {
double k;
double root = a / 2;
do {
k = root;
root = 0.5*(k+ (a / k));
} while ((k - root) != 0);
return root;`
}
共 (0) 个答案