We need to take the square root of a double with an accuracy within 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)>0.0001){if(mid*mid<n){left = mid; }else{ right = mid; } mid = (left+right)/2; } return mid; }