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

news/2024/5/19 6:03:30 标签: java, jvm, jdk, python, 反射

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


http://www.niftyadmin.cn/n/1253745.html

相关文章

java父目录不存在创建_在Java中创建目录以及所需的不存在的父目录

java父目录不存在创建The task is to create directory along with required nonexistent directories. 任务是创建目录以及所需的不存在的目录。 To create directory along with required nonexistent directory, we use mkdirs() method which is a predefined method of &…

c ++类成员函数_C ++ | 创建一个空类(没有数据成员和成员函数的类)

c 类成员函数In the below program, we are creating a C program to create an empty class (a class without data members and member functions). 在下面的程序中&#xff0c;我们正在创建一个C 程序来创建一个空类(一个没有数据成员和成员函数的类) 。 #include <iost…

Haproxy+Nginx

主 dd从 dd1 dd2 #从dd1 dd2同配置useradd -M -s /sbin/logoin nginx./configure \-prefix/usr/local/nginx \-usernginx \-groupnginxmake&&make installln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/echo "<h1>SERVER1</h1>">/usr/l…

python打印变量类型_Python | 声明不同类型的变量,打印其值,类型和ID

python打印变量类型Declare different types of variables; print their types, ids and variables in Python. 声明不同类型的变量&#xff1b; 在Python中打印其类型&#xff0c;id和变量。 There are two inbuilt functions are using in the program: 程序中使用了两个内置…

最长回文子串的求解(java)

根据时间复杂度区别方法&#xff1a; 1、O(n3) 暴力破解 step&#xff1a;首先遍历出所有子串&#xff0c;然后针对每一个子串都判断一下是否为回文子串&#xff0c;是的话判断是否为最长的回文串。 2、O(n2) 中心扩展 step&#xff1a;遍历字符串的每一个字符&#xff0c;以之…

小程序自定义单个页面标题栏_在单个Java程序中使用所有用户定义的异常关键字...

小程序自定义单个页面标题栏As we know that Java provides an efficient mechanism for handling the exception but still user has the option to define its own exception in Java, using try-catch blocks or using throw keyword. List of various user-defined excepti…

0.1+0.2!==0.3

因为机器只能识别2进制&#xff0c;所以结果是一个无限接近0.3的数字0.30000000000000004 那怎么处理这种情况&#xff1a; ES6中提供了这样一个属性&#xff1a;Number.EPSILON&#xff0c;而这个值正等于2^-52&#xff0c;这个值非常非常小&#xff0c;并且无限接近0&#xf…

finalize java_受保护的Java对象类void finalize()抛出带有示例的Throwable方法

finalize java受保护的对象类void finalize()引发Throwable (Object Class protected void finalize() throws Throwable) This method is available in java.lang.Object.finalize(). 此方法在java.lang.Object.finalize()中可用。 This method is called by the garbage coll…