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

java中的starts

数学类静态float nextAfter(浮动开始,双向) (Math Class static float nextAfter(float starts , double directions) )

  • This method is available in java.lang package.

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

  • This method is used to return the float 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 float, it returns the float floating-point number adjacent to start in the direction of the second argument.

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

  • In this method, we pass two parameters first is of float type and second one is of double, 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 float nextAfter(float 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 float, 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 "float.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.

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

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

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

  • If we pass "float.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.

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

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

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

public class NextAfterFloatTypeMethod {
    public static void main(String[] args) {
        //declaring variables
        float f1 = -2.6f;
        float f2 = 0.0f;
        double d3 = 0.0;
        double d4 = -7.0 / 0.0;

        // displaying the values
        System.out.println("f1: " + f1);
        System.out.println("f2: " + f2);
        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.6f,0.0)
        System.out.println("Math.nextAfter (f1,d3): " + Math.nextAfter(f1, d3));

        // Here , we will get (Float.MAX_VALUE) and we are passing 
        // parameter whose value is (0.0f,-7.0/0.0)
        System.out.println("Math.nextAfter (f1,d3): " + Math.nextAfter(f2, d4));

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

        // Here , we will get (smallest value) and we are passing 
        // parameter whose value is (0.0f,-7.0/0.0)
        System.out.println("Math.nextAfter (f1,d3): " + Math.nextAfter(f2, d4));
    }
}

Output

输出量

E:\Programs>javac NextAfterFloatTypeMethod.java

E:\Programs>java NextAfterFloatTypeMethod
f1: -2.6
f2: 0.0
d3: 0.0
d4: -Infinity
Math.nextAfter (f1,d3): -2.5999997
Math.nextAfter (f1,d3): -1.4E-45
Math.nextAfter (f1,d3): -2.5999997
Math.nextAfter (f1,d3): -1.4E-45


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

java中的starts

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值