Java如何计算数字的立方根和平方根?
要计算值的立方根和平方根,double我们可以使用Math.cbrt(doublea)和Math.sqrt(doublea)静态方法调用。
package org.nhooo.example.math;
public class CubeSquareRootExample {
public static void main(String[] args) {
double cube = 125.0d;
double square = 100.0d;
//获取双精度值的多维数据集根
double cubeRoot = Math.cbrt(cube);
System.out.println("Cube root of " + cube + " is " + cubeRoot);
//获取双值的平方根
double squareRoot = Math.sqrt(square);
System.out.println("Square root of " + square + " is " + squareRoot);
}
}此代码段将打印以下输出:
Cube root of 125.0 is 5.0 Square root of 100.0 is 10.0
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短