Java Math max() 方法

定义和用法

max() 方法返回一对数字中具有最高值的数字。

提示:使用 min() 方法返回最小值的数字。

实例

从不同的数字对中获取最大值:

System.out.println(Math.max(2.0, 0.25));
System.out.println(Math.max(31.2f, 18.0f));
System.out.println(Math.max(14, 22));
System.out.println(Math.max(96L, 2048L));

亲自试一试

语法

以下之一:

public static double max(double x, double y)
public static float max(float x, float y)
public static int max(int x, int y)
public static long max(long x, long y)

参数

参数 描述
x 必需。数字。
y 必需。数字。

技术细节

返回: 表示两个数字中最高的 doublefloatintlong 值。
Java 版本: 任意版本。