java math max
數學類靜態double max(double d1,double d2) (Math Class static double max(double d1,double d2) )
This method is available in java.lang package.
此方法在java.lang包中可用。
This method is used to return the maximum one of both the given arguments in the method or in other words it returns the largest value of the given two arguments.
此方法用于返回方法中兩個給定參數中的最大值,換句話說,它返回給定兩個參數中的最大值。
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 largest element from the given two arguments (which are of double types).
此方法的返回類型為double ,它從給定的兩個參數(均為double類型)中返回最大的元素。
In this method, we pass two double values parameters as an argument.
在此方法中,我們傳遞兩個雙精度值參數作為參數。
This method does not throw any exception.
此方法不會引發任何異常。
Syntax:
句法:
public static double max(double d1, double d2){
}
Parameter(s): double d1, double d2 – two double values, in which we have to find the largest value.
參數: double d1,double d2 –兩個double值,我們必須在其中找到最大值。
Return value:
返回值:
The return type of this method is double, it returns the largest/maximum value.
此方法的返回類型為double ,它返回最大值/最大值。
Note:
注意:
If we pass "NaN", it returns "NaN".
如果我們傳遞“ NaN”,則返回“ NaN”。
If we pass the same value as both parameters, it returns the same value.
如果我們為兩個參數傳遞相同的值,則它將返回相同的值。
Java程序演示max(double d1,double d2)方法的示例 (Java program to demonstrate example of max(double d1, double d2) method)
// Java program to demonstrate the example of
// max(double d1, double d2) method of Math Class
public class MaxDoubleTypeMethod {
public static void main(String[] args) {
// declaring the variables
double d1 = -0.0;
double d2 = 0.0;
double d3 = -0.6;
double d4 = 124.68;
// 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 (0.0) because we are
// passing parameter whose value is (-0.0,0.0)
System.out.println("Math.max(d1,d2): " + Math.max(d1, d2));
// Here , we will get (124.68) and we are
// passing parameter whose value is (0.0,124.68)
System.out.println("Math.max(d2,d4): " + Math.max(d2, d4));
}
}
Output
輸出量
E:\Programs>javac MaxDoubleTypeMethod.java
E:\Programs>java MaxDoubleTypeMethod
d1: -0.0
d2: 0.0
d3: -0.6
d4: 124.68
Math.max(d1,d2): 0.0
Math.max(d2,d4): 124.68
翻譯自: https://www.includehelp.com/java/math-class-static-double-max-double-d1-double-d2-with-example.aspx
java math max