public class Newton {

  // code for exercise 9

    private static final float EPSILON = .000001f;

    public static float newtonSqrt(float x) {
      assert x >= 0 : "newtonSqrt: x should be >= 0";
      return findSqrt(x, x / 2);
    }

    private static float findSqrt(float x, float a) {

      float result = a;
      while (Math.abs(x - result * result) >= EPSILON) {
        result = (result + x / result) / 2;
      }
      return result;
    }

}
