Java 教程 Java max() 方法

thurman · 2022-05-24 23:03:38 · 热度: 34

max() 方法用于返回两个参数中的最大值。

语法

该方法有以下几种语法格式:

double max(double arg1, double arg2)
float max(float arg1, float arg2)
int max(int arg1, int arg2)
long max(long arg1, long arg2)

参数

该方法接受两个原生数据类型作为参数。

返回值

返回两个参数中的最大值。

实例

public class Test{
    public static void main(String args[]){
        System.out.println(Math.max(12.123, 18.456));      
        System.out.println(Math.max(23.12, 23.0));  
    }
}

编译以上程序,输出结果为:

18.456
23.12

查看更多 Java Number & Math 类 相关内容

猜你喜欢:
暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册