Java Math min() 方法
示例
从不同的数字对中找出最小值:
System.out.println(Math.min(2.0, 0.25));
System.out.println(Math.min(31.2f, 18.0f));
System.out.println(Math.min(14, 22));
System.out.println(Math.min(96L, 2048L));
定义和用法
min() 方法返回一对数字中较小的那个。
提示: 使用 max() 方法返回较大的那个。
语法
以下选项之一:
public static double min(double x, double y)
public static float min(float x, float y)
public static int min(int x, int y)
public static long min(long x, long y)
参数值
| 参数 | 描述 |
|---|---|
| x | 必需。请输入一个数字。 | y | 必需。请输入一个数字。 |
技术细节
| 返回值: | 返回一个 double、float、int 或 long 值,表示两个数中较小的那个。 |
|---|---|
| Java 版本: | 任意 |
❮ Math 数学方法

