二分发求解
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
Double num = scan.nextDouble();
double left = 0, right = num, mid = 0;
//一定要注意边界条件,输入的num可能是负数 将x<-1的边界范围定为[x,1],x>1的边界范围定为[-1,x]
right = Math.max(1.0,num);
left = Math.min(-1.0,num);
while(right - left > 0.01){
mid = left + (right - left) / 2;
if(mid * mid * mid < num){
left = mid;
}else if(mid * mid * mid > num){
right = mid;
}else{
return;
}
}
System.out.printf("%.1f",mid);
}
}
}