There are several techniques for implementingthe sqrt method in the Math class. One such technique is known as theBabylonian method. It approximates the square root of a number, n, by repeatedlyperforming the calculation using the following formula:nextGuess = (lastGuess + n / lastGuess) / 2When nextGuess and lastGuess are almost identical, nextGuess is theapproximated square root. The initial guess can be any positive value (e.g., 1).This value will be the starting value for lastGuess. If the difference betweennextGuess and lastGuess is less than a very small number, such as 0.0001,you can claim that nextGuess is the approximated square root of n. If not, nextGuessbecomes lastGuess and the approximation process continues. Implementthe following method that returns the square root of n:public static double sqrt(long n)

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter4: Selection Structures
Section: Chapter Questions
Problem 14PP
icon
Related questions
Question

There are several techniques for implementing
the sqrt method in the Math class. One such technique is known as the
Babylonian method. It approximates the square root of a number, n, by repeatedly
performing the calculation using the following formula:
nextGuess = (lastGuess + n / lastGuess) / 2
When nextGuess and lastGuess are almost identical, nextGuess is the
approximated square root. The initial guess can be any positive value (e.g., 1).
This value will be the starting value for lastGuess. If the difference between
nextGuess and lastGuess is less than a very small number, such as 0.0001,
you can claim that nextGuess is the approximated square root of n. If not, nextGuess
becomes lastGuess and the approximation process continues. Implement
the following method that returns the square root of n:
public static double sqrt(long n)

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr