- public class MySqrt {
- public static void main(String[] args) {
- double number = 2;
- //求一个指定数以内的值
- double randomValue = new Random().nextInt((int)number);
-
- System.out.println(sqrt(number,randomValue,7));
-
- }
- public static double sqrt(double number,double randomValue,int flag){
- double result = (randomValue + number / randomValue)/2;
- flag--;
- if(flag == 0){
- return result;
- }
- return sqrt(number,result,flag);
- }
- }
复制代码 |