Java.lang.Double 类

java.lang.Double.max() 方法返回两个双精度值中较大的一个,就像调用 Math.max 一样.

语法

public static double max(double a,
                         double b)

参数

a 指定第一个操作数.
b 指定第二个操作数。

返回值

返回 a 和 b 中的较大者。

异常

无。

示例:

在下面的示例中,java.lang.Double.max() 方法返回传递的两个双精度参数中的较大者。

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //创建双精度值
    double x = 5.2;
    double y = 10.2;

    //打印两个双精度值中的最大值
    System.out.println("max(x, y) = " + Double.max(x, y));   
  }
}

上述代码的输出将是:

max(x, y) = 10.2