牛顿迭代法
1 package leetcode; 2 3 public class demo_69 { 4 public int mySqrt(int x) { 5 long t=x; 6 while(t*t>x) { 7 t=(t+x/t)/2; 8 } 9 return (int)t; 10 } 11 public static void main(String[] args) { 12 // TODO Auto-generated method stub 13 demo_69 d69=new demo_69(); 14 System.out.println(d69.mySqrt(5)); 15 } 16 17 }