JAVA Program The ancients had a recursive method for calculating a square root:
ID: 3673022 • Letter: J
Question
JAVA Program
The ancients had a recursive method for calculating a square root: Suppose you want to find the square root of x, guess that the square root is x/2. Test your guess (what's the difference between x and guess*guess). If your guess isn't accurate enough, try again. Your new guess should be 0.5 * (last guess + X/last guess). Keep going until your guess is close enough. Your class should include a recursive method for calculating the square root using the Babylonian Method. Users of your class should be able to specify the number they'd like to take a square root of as well as how much error they will tolerate in the square root estimation. For testing purposes, you should print the output.Explanation / Answer
Step 1. Estimate the square root of the given positive integer. We will shortly learn how to make good estimates, not wild estimates. Step 2 (The crux of the method). Calculate the average of that guess and the given positive integer divided by that guess. Step 3. Use your answer to Step 2 as your new guess and repeat Step 2 (this is the “recursion”) until the desired degree of accuracy is obtained. Recall that average (or mean) is a measure of the central tendency of a group of numbers. Since we are taking the average of two numbers, the “central tendency” of these two numbers will be the number halfway between. To find the average of any two numbers, 3 and 5 for example, we add them and then divide the sum by 2; i.e., 35 8 4 2 2 . 3 Hence, the average of 3 and 5 is 4. This makes perfect sense because, on a numberline, 4 is halfway b
etween 3 and 5. Before we apply this method, let’s see if we can refine our skills of guessing. Suppose we want to find the square root of a positive integer. We know that the lengths of the digits in a positive integer can be either odd or even. We are going to make use of this fact to help us make accurate first guesses of the square root of any positive integer
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.