java中的starts_Java Math类静态double nextAfter(double starts,double direction)示例

java中的starts

数学类静态double nextAfter(双向启动,双向) (Math Class static double nextAfter(double starts , double directions) )

  • This method is available in java.lang package.

    此方法在java.lang包中可用。

  • This method is used to return the double floating-point number adjacent to the first parameter (starts) in the direction of the second parameter (directions).

    此方法用于在第二个参数(方向)的方向上返回与第一个参数相邻的双浮点数(起始)。

  • Let suppose both arguments passed in the method are equivalent so in that case the second parameter is returned.

    假设在方法中传递的两个参数都相等,那么在这种情况下将返回第二个参数。

  • This is a static method, so it is accessible with the class name too.

    这是一个静态方法,因此也可以使用类名进行访问。

  • The return type of this method is double, it returns the double floating-point number adjacent to start in the direction of the second argument.

    此方法的返回类型为double ,它返回第二个参数方向上与start相邻的double浮点数。

  • In this method, we pass two parameters of double type so the first parameter represents the initial or starting floating-point value and the second parameter represents the value denoting which of the given first parameter neighbor (Starts neighbor) or start is returned.

    在此方法中,我们传递了两个双精度类型的参数,因此第一个参数表示初始或起始浮点值,第二个参数表示表示返回给定的第一个参数邻居(起点邻居)或起点的值。

  • This method does not throw any exception.

    此方法不会引发任何异常。

Syntax:

句法:

    public static double nextAfter(double starts , double directions){
    }

Parameter(s):

参数:

  • starts – represents the initial or starting floating-point value.

    starts –表示初始或起始浮点值。

  • directions – represents the value denoting which of the given first parameter neighbor (starts neighbor).

    directions –代表一个值,该值表示给定的第一个参数邻居( 起始邻居)。

Return value:

返回值:

The return type of this method is double, it returns the double floating-point number adjacent to the first parameter (starts) in the direction of second parameter (directions).

这种方法的返回类型是双 ,它在第二个参数( 方向 )的方向返回邻近第一参数( 首发 )的双浮点数。

Note:

注意:

  • If we pass "NaN" (Not a Number), it returns the same i.e. "NaN".

    如果我们传递“ NaN”(不是数字),则返回相同的值,即“ NaN”。

  • If we pass the same value in both of the parameters, it returns the same value.

    如果我们在两个参数中传递相同的值,它将返回相同的值。

  • If we pass "Double.MIN_VALUE" as the first parameter and second parameter holds another value, it returns smaller value i.e. the same value is with the same sign as the first parameter.

    如果我们将“ Double.MIN_VALUE”作为第一个参数传递,而第二个参数包含另一个值,则它将返回较小的值,即,与第一个参数相同的值带有相同的符号。

  • If we pass infinity as first parameter and second parameter holds another value, it returns the "Double.MAX_VALUE" with the same sign as the first parameter.

    如果我们将无穷大作为第一个参数传递而第二个参数包含另一个值,则它将返回与第一个参数具有相同符号的“ Double.MAX_VALUE”。

  • If we pass "Double.MAX_VALUE" as the first parameter and second parameter holds another value, it returns the largest value with the same sign as the first parameter.

    如果我们将“ Double.MAX_VALUE”作为第一个参数传递,而第二个参数保留另一个值,则它将返回与第一个参数具有相同符号的最大值。

Java程序演示nextAfter(double starts,双向)方法的示例 (Java program to demonstrate example of nextAfter(double starts , double directions) method)

// Java program to demonstrate the example of 
// nextAfter(double starts , double directions) method of Math Class.

public class NextAfterDoubleTypeMethod {
    public static void main(String[] args) {
        // declaring the variables
        double d1 = -2.6;
        double d2 = 0.0;
        double d3 = -0.6;
        double d4 = 7.0 / 0.0;

        // displaying the values
        System.out.println("d1: " + d1);
        System.out.println("d2: " + d2);
        System.out.println("d3: " + d3);
        System.out.println("d4: " + d4);

        // Here , we will get (-2.5 (approx.)) because we are passing 
        // parameter whose value is (-2.6,0.0)
        System.out.println("Math.nextAfter(d1,d2):" + Math.nextAfter(d1, d2));

        // Here , we will get (2.6) and we are passing parameter 
        // whose value is (0.0,-2.6)
        System.out.println("Math.nextAfter(d2,d1):" + Math.nextAfter(d2, d1));

        // Here , we will get (Double.MAX_VALUE) and we are passing parameter
        // whose value is (7.0/0.0,0.0)
        System.out.println("Math.nextAfter(d4,d2):" + Math.nextAfter(d4, d2));

        // Here , we will get (largest value) and we are passing parameter 
        // whose value is (0.0,7.0/0.0)
        System.out.println("Math. nextAfter(d2,d4):" + Math.nextAfter(d2, d4));
    }
}

Output

输出量

E:\Programs>javac NextAfterDoubleTypeMethod.java

E:\Programs>java NextAfterDoubleTypeMethod
d1: -2.6
d2: 0.0
d3: -0.6
d4: Infinity
Math.nextAfter(d1,d2):-2.5999999999999996
Math.nextAfter(d2,d1):-4.9E-324
Math.nextAfter(d4,d2):1.7976931348623157E308
Math. nextAfter(d2,d4):4.9E-324


翻译自: https://www.includehelp.com/java/math-class-static-double-nextafter-double-starts-double-directions-with-example.aspx

java中的starts

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值