目录

static long max(long a, long b)

描述 (Description)

java.lang.StrictMath.max(long a, long b)方法返回两个long值中较大的一个。 也就是说,结果是参数更接近Long.MAX_VALUE的值。 如果参数具有相同的值,则结果是相同的值。

声明 (Declaration)

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

public static long max(long a, long b)

参数 (Parameters)

  • a - 这是长值。

  • b - 这是另一个长值。

返回值 (Return Value)

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

异常 (Exception)

NA

例子 (Example)

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

package com.iowiki;
import java.lang.*;
public class StrictMathDemo {
   public static void main(String[] args) {
      long l1 = 4355335 , l2 = 8887765, l3 = -3255697;
      // both positive values
      double maxValue = StrictMath.max(l1, l2); 
      System.out.println("StrictMath.max(4355335, 8887765) : " + maxValue);
      // one positive and one negative value
      maxValue = StrictMath.max(l1, l3); 
      System.out.println("StrictMath.max(4355335, -3255697) : " + maxValue);    
   }
}

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

StrictMath.max(4355335, 8887765) : 8887765.0
StrictMath.max(4355335, -3255697) : 4355335.0
↑回到顶部↑
WIKI教程 @2018