Newton Raphson Method(a very optimized way to find root)
Dec 12, 2022
public class NewtonRaphson{
public static void main(String[] args) {
System.out.printf("%.3f",sqrt(423749));
}
static double sqrt(int n){
double x = n;
double root;
while(true){
root = (x + n/x)/2;
if(Math.abs(root-x) < 1){
break;
}
x = root;
}
return root;
}
}