Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Consider a method with this heading: public static void print Sqrt (double x) The method prints the square root of x to the standard output. Write a reasonable specification for this method and...

1 answer below »

Consider a method with this heading: public static void print Sqrt (double x) The method prints the square root of x to the standard output. Write a reasonable specification for this method and compare your answer to the solution at the end of the chapter. The specification should forbid a negative argument.

 

Answered 114 days After May 13, 2022

Solution

Kshitij answered on Sep 05 2022
70 Votes
public static void printSqrt(double x) {
double p = 0.001;
double guess = x / 2;
while( Math.abs( guess*guess - x ) > p) {
guess = ( guess + ( x / guess ) ) / 2;
}
float ans = (float) guess;
System.out.println(ans);
}
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here