Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 用对数循环计算立方体_Java - Fatal编程技术网

Java 用对数循环计算立方体

Java 用对数循环计算立方体,java,Java,我需要构建一个循环来实现这一点:3=Math.log10(数字平方的结果)/Math.log10(数字输入)数字要立方化 double cubed; double answer; answer = 1; cubed = 0; while (cubed <= 3) { cubed = (double) Math.log( answer )/Math.log( number_to_be_cubed ); answer ++; } double answer_for_cub

我需要构建一个循环来实现这一点:3=Math.log10(数字平方的结果)/Math.log10(数字输入)数字要立方化

double cubed;
double answer;

answer = 1;
cubed = 0;

while (cubed <= 3) {
    cubed = (double) Math.log( answer )/Math.log( number_to_be_cubed );
    answer ++;
}

double answer_for_cubed = answer;
System.out.println("answer_for_cubed  " + answer_for_cubed);
双立方;
双重回答;
答案=1;
立方=0;
而(立方这是有效的

 public static void main(String[] args) {

    Double cubed = 0d;
    Double answer = 0d;

    while (cubed.compareTo(3d) <0) {
        answer ++;
        cubed = Math.log( answer )/Math.log( 4 );
        System.out.println(cubed + "   " + answer);
    }

    double answer_for_cubed = answer;
    System.out.println("answer_for_cubed  " + answer_for_cubed);
}

您可能想提到,此方法仅在
number\u-to\u-cubed
整数时有效。例如,尝试
Math.log(answer)/Math.log(4.2)
,预期答案为
74.1
,但这会计算
75
answer_for_cubed  64.0