The ancient Greeks knew how to efficiently compute square roots. If you want the square root of a and already have a guess xold for it, then you can have a better guess as the average of xold and a / xold, i.e.
xnew = (xold + a / xold) x 0.5
For the initial guess, set xold to a.
Implement a program that reads a, and n, and that prints all guesses other than the initial one, until two of them are less than 10-n apart. Use BigDecimal
.
For the division, use
divide(xold, n + 1, RoundingMode.HALF_EVEN)