Java, Java, Java 3E

Chapter 6: Control Structures
Ch 6 Lab: Newton's Method for Calculating Square Root
Click here to view the lab writeup

Brief description

Newton's method for calculating the square root of N starts by making a (non zero) guess at the square root. It then uses the original guess to calculate a new guess, according to the following formula:
    
       guess = (( N / guess) + guess) / 2 ;
If we repeat this calculation the algorithm will eventually find the square root of N.

This lab involves designing a Java applet that let's the user input a number N, a maximum error that determines how close Newton's method should come to the actual square root. The program should calculate the square root using Newton's method and report both the square root and the number of guesses required to calculate it. It requires a conditional loop.

The objectives of this lab are:

Here's a demo program:


NewtonTestApplet