目录

static int max(int a, int b)

描述 (Description)

java.lang.Math.max(int a, int b)返回两个int值中的较大者。 也就是说,结果是更接近正无穷大的论证。 如果参数具有相同的值,则结果是相同的值。 如果任一值为NaN,则结果为NaN。 与数值比较运算符不同,此方法将负零视为严格小于正零。 如果一个参数为正零而另一个参数为负零,则结果为正零。

声明 (Declaration)

以下是java.lang.Math.max()方法的声明

public static int max(int a, int b)

参数 (Parameters)

  • a - 一个论点

  • b - 另一个论点

返回值 (Return Value)

此方法返回a和b中较大的一个。

异常 (Exception)

NA

例子 (Example)

以下示例显示了lang.Math.max()方法的用法。

package com.iowiki;
import java.lang.*;
public class MathDemo {
   public static void main(String[] args) {
      // get two integer numbers
      int x = 60984;
      int y = 1000;
      // print the larger number between x and y
      System.out.println("Math.max(" + x + "," + y + ")=" + Math.max(x, y));
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

Math.max(60984, 1000)=60984
↑回到顶部↑
WIKI教程 @2018