//  Data Structures with Java by John R. Hubbard
//  Copyright McGraw-Hill, 2001
//  Example 1.12 on page 16
//  Testing the Math.sqrt() method

public class Ex0112
{ public static void main(String[] args)
  { for (double x=50.0; x<60.0; x++)
    { double y=Math.sqrt(x);
      double z=sqrt(x);
      System.out.println(y + "\t" + y*y);
      System.out.println(z);
    }
  }
  
  private static double sqrt(double x)
  { final double EPSILON=1E-14;
    if (x <= 0) return 0.0;
    double y=1.0;
    while (Math.abs(y*y-x) > EPSILON)
      y = (y+x/y)/2;
    return y;
  }
}
