Created
February 21, 2017 20:19
-
-
Save sdmg15/171cce2e41b1c80aac11d8d29159c683 to your computer and use it in GitHub Desktop.
Computing the square root of a given number using Newton method's.
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