Java Math max() 方法
示例
獲取不同數字對中的最高值
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));
定義和用法
max() 方法返回一對數字中具有最高值的數字。
提示:使用 min() 方法返回具有最低值的數字。
語法
以下之一
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 | 必需。一個數字。 |
技術詳情
| 返回 | 一個 double、float、int 或 long 值,表示兩個數字中的最高值。 |
|---|---|
| Java 版本 | 任何 |
❮ Math 方法