题目描述
blablabla
样例
blablabla
算法
import java.util.*;
public class Main {
public static void main(String args[]){
Scanner nums = new Scanner(System.in);
double n = nums.nextDouble();
int fuHao = 1;
//把负数变为正数
if(n < 0){
fuHao = -1;
n = -n;
}
double l = 0;
double r = 0;
double mid = 0;
double cha = 0;
double deta = 0;
if(n >= 1){
l = 0;
r = n;
mid = ( l + r ) / 2;
cha = mid * mid * mid - n;
deta = Math.abs(cha);
}else{
l = n;
r = 1;
mid = ( l + r ) / 2;
cha = mid * mid * mid - n;
deta = Math.abs(cha);
}
while(deta >= 0.0000000001){
if(cha > 0){
r = mid;
}else{
l = mid;
}
mid = ( l + r ) / 2;
cha = mid * mid * mid - n;
deta = Math.abs(cha);
}
mid = mid * fuHao;
System.out.printf("%.6f",mid);
}
}