该方法给出了两个参数的最大值。参数可以是int,float,long,double。
句法
- double max(double arg1, double arg2)
- float max(float arg1, float arg2)
- int max(int arg1, int arg2)
- long max(long arg1, long arg2)
参数 - 此方法接受任何原始数据类型作为参数。
返回值 - 此方法返回两个参数的最大值。
例子
下面是一个使用这个方法的例子 -
- class Example {
- static void main(String[] args) {
- System.out.println(Math.max(12.123, 12.456));
- System.out.println(Math.max(23.12, 23.0));
- }
- }
当我们运行上面的程序,我们将得到以下结果 -
- 12.456
- 23.12
转载本站内容时,请务必注明来自W3xue,违者必究。