```
public class Solution {
public int mySqrt(int x) {
if(x == 0)
return x;
double dividend = x;
double val = x;
double last;
do
{
last = val;
val=(val + dividend/val)*0.5;
}while(Math.abs(val - last) > 1e-9);
return (int)val;
}
}
```