Java.lang.StrictMath.max() 方法
描述
java.lang.StrictMath.max(int a, int b) 方法返回两个 int 值中的较大者。 也就是说,结果是更接近 Integer.MAX_VALUE 值的参数。 如果参数具有相同的值,则结果是相同的值。
声明
以下是 java.lang.StrictMath.max() 方法的声明。
public static int max(int a, int b)
参数
a − 这是 int 值。
b − 这是另一个 int 值。
返回值
此方法返回 a 和 b 中较大的一个。
异常
NA
示例
下面的例子展示了 java.lang.StrictMath.max() 方法的使用。
package com.tutorialspoint;
import java.lang.*;
public class StrictMathDemo {
public static void main(String[] args) {
int i1 = 45 , i2 = 20, i3 = -15;
// both positive values
double maxValue = StrictMath.max(i1, i2);
System.out.println("StrictMath.max(45, 20) : " + maxValue);
// one positive and one negative value
maxValue = StrictMath.max(i1, i3);
System.out.println("StrictMath.max(45, -15) : " + maxValue);
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
StrictMath.max(45, 20) : 45.0 StrictMath.max(45, -15) : 45.0

