strictmath_Java StrictMath cbrt()方法与示例

strictmath

StrictMath类cbrt()方法 (StrictMath Class cbrt() method)

  • cbrt() method is available in java.lang package.

    cbrt()方法在java.lang包中可用。

  • cbrt() method is used to find the cube root of the given parameter in the method. Here, cbrt stands for cube root.

    cbrt()方法用于查找方法中给定参数的立方根。 在这里, cbrt代表cube root

  • cbrt() method is a static method so it is accessible with the class name and if we try to access the method with the class object then we will not get an error.

    cbrt()方法是一个静态方法,因此可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会收到错误。

  • In this method, if we pass a positive parameter so it returns the cube root of the given parameter with the same sign(Positive) else if we pass negative parameter so it returns the cube root of the given parameter with the same sign(Negative).

    在此方法中,如果传递正参数,则返回给定参数的立方根(正);否则,传递负参数,使它返回给定参数的立方根(负) 。

  • cbrt() method does not throw any exception.

    cbrt()方法不会引发任何异常。

Syntax:

句法:

    public static double cbrt(double d);

Parameter(s):

参数:

  • double d – represents a double type value whose cube root to be found.

    double d –表示要查找其立方根的double类型值。

Return value:

返回值:

The return type of this method is double – it returns the cube root of given angle.

此方法的返回类型为double-返回给定角度的立方根。

Note:

注意:

  • If we pass NaN as an argument, method returns the same value (NaN).

    如果我们将NaN作为参数传递,则方法将返回相同的值(NaN)。

  • If we pass zero (0), method returns the same value with the same sign.

    如果传递零(0),则方法将返回具有相同符号的相同值。

  • If we pass an infinity, method returns the same value with the same sign.

    如果我们传递一个无穷大,则方法将返回带有相同符号的相同值。

Example:

例:

// Java program to demonstrate the example
// of  cbrt(double d) method of StrictMath Class.

public class Cbrt {
    public static void main(String[] args) {
        // variable declarations
        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;

        // Display previous value of d1,d2,d3,d4,d5 and 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);

        // Here , we will get (-0.0) because we are 
        // passing parameter (-0.0) so the cube root is the same
        System.out.println("StrictMath.cbrt(d1): " + StrictMath.cbrt(d1));

        // Here , we will get (0.0) because we are 
        // passing parameter (0.0) so the cube root is the same
        System.out.println("StrictMath.cbrt(d2): " + StrictMath.cbrt(d2));

        // Here , we will get (-Infinity) because we are 
        // passing parameter (-7.0/0.0) so the cube root is (-Infinity)
        System.out.println("StrictMath.cbrt(d3): " + StrictMath.cbrt(d3));

        // Here , we will get (Infinity) because we are 
        // passing parameter (7.0/0.0) so the cube root is (Infinity)
        System.out.println("StrictMath.cbrt(d4): " + StrictMath.cbrt(d4));

        // Here , we will get (10.0) because we are
        // passing parameter (1000.0) so the cube root is 10.0
        System.out.println("StrictMath.cbrt(d5): " + StrictMath.cbrt(d5));

        // Here , we will get (-10.0) because we are
        // passing parameter (-1000.0) so the cube root is (-10.0)
        System.out.println("StrictMath.cbrt(d6): " + StrictMath.cbrt(d6));
    }
}

Output

输出量

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


翻译自: https://www.includehelp.com/java/strictmath-cbrt-method-with-example.aspx

strictmath

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值