Respuesta :
Answer:
Check the explanation
Explanation:
package com.squarerrot;
public class SquareRoot {
/**
*
*/
public static double squareRoot(double input) {
System.out.println("Trace for input:" + input);
//random value initialized to 6 here
double output, guessValue = 6, previousValue = 0;
while (input - (output = approximateValue(input, guessValue)) >= 0.00005
&& previousValue != output) {
guessValue = output;
previousValue = output;
System.out.println(output);
}
return output;
}// end of method squareRoot
// calculate the approximate value
public static double approximateValue(double input, double start) {
return (start + (input / start)) / 2;
}// end of method approximateValue
// test the square root method
public static void main(String[] args) {
System.out.println("Square Root of 9:" + squareRoot(9));
System.out.println("Square Root of 16:" + squareRoot(16));
}// end of method main
}// end of the class