Java StrictMath cbrt()方法与示例
StrictMath类cbrt()方法
cbrt()方法在java.lang包中可用。
cbrt()方法用于查找方法中给定参数的立方根。在这里,cbrt代表cuberoot。
cbrt()方法是一个静态方法,因此可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会出错。
在此方法中,如果传递正参数,则返回给定参数的立方根(正);否则,传递负参数,使它返回给定参数的立方根(负)。
cbrt()方法不会引发任何异常。
语法:
public static double cbrt(double d);
参数:
doubled–表示要查找其立方根的double类型值。
返回值:
此方法的返回类型为double-返回给定角度的立方根。
注意:
如果我们将NaN作为参数传递,则方法将返回相同的值(NaN)。
如果传递零,则方法将返回具有相同符号的相同值。
如果我们传递一个无穷大,则方法将返回带有相同符号的相同值。
示例
//Java程序演示示例
//StrictMath类的cbrt(doubled)方法。
public class Cbrt {
public static void main(String[] args) {
//变量声明
double d1 = -0.0;
double d2 = 0.0;
double d3 = -7.0 / 0.0;
double d4 = 7.0 / 0.0;
double d5 = 1000.0;
double d6 = -1000.0;
//显示d1,d2,d3,d4,d5和d6的先前值
System.out.println("d1: " + d1);
System.out.println("d2: " + d2);
System.out.println("d3: " + d3);
System.out.println("d4: " + d4);
System.out.println("d5: " + d5);
System.out.println("d6: " + d6);
//在这里,我们得到(-0.0),因为我们
//传递参数(-0.0),因此多维数据集根相同
System.out.println("StrictMath.cbrt(d1): " + StrictMath.cbrt(d1));
//在这里,我们得到(0.0),因为我们
//传递参数(0.0),因此多维数据集根相同
System.out.println("StrictMath.cbrt(d2): " + StrictMath.cbrt(d2));
//在这里,我们将得到(-Infinity),因为我们
//传递参数(-7.0/0.0),因此多维数据集根为(-Infinity)
System.out.println("StrictMath.cbrt(d3): " + StrictMath.cbrt(d3));
//在这里,我们将得到(Infinity),因为我们
//传递参数(7.0/0.0),因此多维数据集根为(Infinity)
System.out.println("StrictMath.cbrt(d4): " + StrictMath.cbrt(d4));
//在这里,我们得到(10.0),因为我们
//传递参数(1000.0),因此多维数据集根为10.0-
System.out.println("StrictMath.cbrt(d5): " + StrictMath.cbrt(d5));
//在这里,我们将得到(-10.0),因为我们
//传递参数(-1000.0),因此多维数据集根为(-10.0)
System.out.println("StrictMath.cbrt(d6): " + StrictMath.cbrt(d6));
}
}输出结果
d1: -0.0 d2: 0.0 d3: -Infinity d4: Infinity d5: 1000.0 d6: -1000.0 StrictMath.cbrt(d1): -0.0 StrictMath.cbrt(d2): 0.0 StrictMath.cbrt(d3): -Infinity StrictMath.cbrt(d4): Infinity StrictMath.cbrt(d5): 10.0 StrictMath.cbrt(d6): -10.0