/**************************************************************
 * Newton's Method for Square Roots
 * Mark Goadrich
 * CSC 204 - Spring 2008
 **************************************************************/
public class Sqrt{

    // main method to run the program
    public static void main(String[] args) {
        
        // get number c for calculation from the user
        double c = Double.parseDouble(args[0]);
	
	// initialize variable, size of error and first guess
	double epsilon = 1e-15;
	double t = c;

	// repeat until error small enough
	while (Math.abs(t - c/t) > epsilon * t) {

	    // recalibrate guess t to be average
	    t = (c/t + t) / 2.0;
	}
	
	// display result to user
	System.out.println(t);
    }
}

