You have been given an algorithm. What steps have you taken to code it in Java?
Show us your work; tell us where you are stuck; then we can give you a hand.
double sqrt(double x) {
if (x <= 0)
throw new IllegalArgumentException("x not positive");
double ne = x/2 ;
double pe = x ;
while ( Math.abs(ne-pe) > 0.0001) {
pe = ne ;
ne = (pe + x / pe) / 2;
}
return ne ;
}
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
23 Experts available now in Live!