Created
February 27, 2017 17:50
-
-
Save devteampentagon/e68089b1e19f4ec3257b21c5368f1120 to your computer and use it in GitHub Desktop.
Computing the square root of a given number using Newton method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner ; | |
public class sdz { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
System.out.println(squaroot(2,16,0.05)); | |
} | |
static double squaroot(int start, double number , double precision){ | |
double u0 = start; | |
double un; | |
do { | |
un = u0; | |
u0 = 0.5*(un + number/un); | |
}while(Math.abs(un-u0)> precision); | |
return u0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment