Java.lang.StrictMath 类

java.lang.StrictMath.max() 方法返回两个参数之间的最大数字。如果任一参数为 NaN,则结果为 NaN。

语法

public static float max(float a, float b) 

参数

a 指定要比较的值。
b 指定要比较的值。

返回值

返回数值最大值。

异常

无。

示例:

在下面的示例中,max()方法用于找出两个参数之间的最大值。

import java.lang.*;

public class MyClass {
 public static void main(String[] args) {
  float x1 = 50f;
  float y1 = 100f;
  float x2 = 5.5f;
  float y2 = 10.5f;

  System.out.println(StrictMath.max(x1, y1)); 
  System.out.println(StrictMath.max(x2, y2));   
 }
}

上述代码的输出将是:

100.0
10.5