这是我写的第一个代码。这是我的代码的一部分,旨在在用户给出体积值后计算立方体和四面体的边长,但是输出不正确。我很确定我的方程是正确的,也许我错误地使用了 Math.pow 方法?
System.out.println("Now, please enter a volume for side or diameter calculation, then press ENTER: ");
volume = input.nextDouble();
cubeSide = Math.pow(volume, (1/3));
sphereDiameter = Math.pow(volume / PI * 6, (1/3));
tetSide = SQRT_2 * Math.pow(3 * volume, (1/3));
System.out.println("");
System.out.println("The Side of your CUBE is : " + cubeSide);
System.out.println("");
System.out.println("The Diameter of your SPHERE is : " + sphereDiameter);
System.out.println("");
System.out.println("The Side of your TETRAHEDRON is : " + tetSide);
关于如何获得正确输出的任何想法?
最佳答案
1/3
is 0
- 当被除数和除数均为整数时,/
执行整数除法。您需要 1.0/3
或 1/3.0
或 1.0/3.0
,其计算结果为 0.3333333
-ish。
关于java - 使用小数指数的 Math.pow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31258674/