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