Java StrictMath cbrt()方法
java.lang.StrictMath.cbrt() 是Java中的一个内置方法,用于返回一个给定的双数值的立方根。该方法显示了三个特殊的结果。
当给定的参数为零时,其结果是一个与参数符号相同的零。当参数为无穷大时,结果为与参数符号相同的无穷大。当给定参数为NaN时,结果为NaN。语法
public static double cbrt( _double num_ )
参数: 该方法接受一个参数 num ,该参数为双数类型,需要找到其立方根。
返回值: 该方法返回 num 的立方根。
以下程序说明了java.lang.StrictMath.cbrt()方法:
程序1 :
// Java program to illustrate the// java.lang.StrictMath.cbrt()import java.lang.*; public class Geeks { public static void main(String[] args) { double val1 = 8.05, val2 = 27, val3 = 0; // It returns the cube root of a double value double cbrtvalue = StrictMath.cbrt(val1); System.out.println("Cube root of "+val1+ " = " + cbrtvalue); cbrtvalue = StrictMath.cbrt(val2); System.out.println("Cube root of "+val2+ " = " + cbrtvalue); cbrtvalue = StrictMath.cbrt(val3); System.out.println("Cube root of "+val3+ " = " + cbrtvalue); }}输出
Cube root of 8.05 = 2.0041580161269152Cube root of 27.0 = 3.0Cube root of 0.0 = 0.0
程序2
// Java program to illustrate the// java.lang.StrictMath.cbrt()import java.lang.*; public class Geeks { public static void main(String[] args) { double val1 = -8.05, val2 = 128, val3 = 0; // It returns the cube root of a double value double cbrtvalue = StrictMath.cbrt(val1); System.out.println("Cube root of "+val1+ " = " + cbrtvalue); cbrtvalue = StrictMath.cbrt(val2); System.out.println("Cube root of "+val2+ " = " + cbrtvalue); cbrtvalue = StrictMath.cbrt(val3); System.out.println("Cube root of "+val3+ " = " + cbrtvalue); }}输出
Cube root of -8.05 = -2.0041580161269152Cube root of 128.0 = 5.039684199579493Cube root of 0.0 = 0.0
