Long before computers, square roots were computed by repeating one formula: if guess is an approximation of √n, then
nextGuess = (guess + n / guess) / 2
is a better one. Start with 1 and stop when two guesses in a row differ by less than 0.00001.
Write MySqrt with the methods sqrt(double n), steps(double n) (how many times the guess was improved) and difference(a, b) (the distance between two numbers, written with an if). main reads numbers until the end of the input and compares your result with Math.sqrt. For the input
2 9 10 0.25 1000000 0
the program prints
sqrt(2.00): mine 1.41421 in 4 steps, Math.sqrt 1.41421
sqrt(9.00): mine 3.00000 in 6 steps, Math.sqrt 3.00000
sqrt(10.00): mine 3.16228 in 6 steps, Math.sqrt 3.16228
sqrt(0.25): mine 0.50000 in 5 steps, Math.sqrt 0.50000
sqrt(1000000.00): mine 1000.00000 in 15 steps, Math.sqrt 1000.00000
sqrt(0.00): mine 0.00000 in 0 steps, Math.sqrt 0.00000