需要给double类型的数据开根号
要求精度在0.0001之内

public double getSqrtNum(double num){
    double left;
    double right;
    double mid;
    if(n<1&&n>0){
        left = num;
        right = 1;
    }
    if(n>1){
        left = 0;
        right = num;
    }
    mid = (left+right)/2;
    while(Math.abs(mid*mid-n)>0.0001){
        if(mid*mid<n){
            left = mid;
        }else{
            right = mid;
        }
        mid = (left+right)/2;
    }
    return mid;
}

fhzmWJ
21 声望0 粉丝