Square Root - iteratively
In the applet on the left, enter a number in the input box
and hit return. The square root of that number shows up in the
output box and the progression of m appears in the
Square Root from 2000 B.C.
- Problem: Fix the problem of iteration uncertainty in finding
square roots using the method of the previous slide.
- Introduce a precision variable of type double (in this
case it is initialized to 0.0000001) and change the for loop
to a do loop so as to test whether m differs from
that of the previous iteration by the precision amount. If
the difference is really small then break out of the loop and print
- A do is used instead of a while because the
condition needs to be tested after m is computed at
- A JTextArea has been added to see the progression toward the