Newton Raphson Method(a very optimized way to find root)

Palakkgoyal
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;
}
}

--

--

Palakkgoyal

Solutions to all your coding related problems at one point. DSA question on daily basis and much more.