go to previous page   go to home page   go to next page

Answer:

No, the absolute value takes care of that.


Near-complete Square Root Program

Here (again) is the recursive procedure:

And here is the square root method, except for a blank. Your job is to fill in the blank.

class  SquareRootRecursive
{
  public static boolean nearlyEquals( double x, double y )
  {
    final double smallValue = 1.0E-14 ;
    return Math.abs( x - y ) < smallValue ;
  }
  
  public static double Newton( double N, double guess )
  {
    if (  )
      return guess;
    else
      return Newton( N, N/(2*guess) + guess/2 );
  }
  
  public static void main( String[] args ) 
  {
    double N     = 3.00 ;
    double guess = 1.00 ;

    System.out.println("The square root of " + N + " is " + Newton( N, guess ) ) ;
  }

}

QUESTION 21:

Fill in the blank.


go to previous page   go to home page   go to next page