Java Math max()
max()
方法返回指定参数中的最大值。
示例
class Main {
public static void main(String[] args) {
// 计算 88 和 98 的最大值
System.out.println(Math.max(88, 98));
}
}
// 输出:98
Math.max() 的语法
max()
方法的语法是:
Math.max(arg1, arg2)
这里,max()
是一个静态方法。因此,我们通过类名 Math
来访问这个方法。
max() 参数
max()
方法接受两个参数。
- arg1/arg2 - 在这些参数中返回最大值
注意:参数的数据类型应该是 int
、long
、float
或 double
。