Java.math.BigInteger.max() 方法



说明

java.math.BigInteger.max(BigInteger val) 返回此 BigInteger 和 val 的最大值。

声明

以下是 java.math.BigInteger.max() 方法的声明。

public BigInteger max(BigInteger val)

参数

val − 用来计算最大值的 value

返回值

此方法返回其值为此与 val 中较大的那个 BigInteger。如果它们相等,则任一一个都可以返回。

异常

不适用

示例

以下示例显示了 math.BigInteger.max() 方法的用法。

package com.tutorialspoint;

import java.math.*;

public class BigIntegerDemo {

   public static void main(String[] args) {

      // create 3 BigInteger objects
      BigInteger bi1, bi2, bi3;

      bi1 = new BigInteger("123");
      bi2 = new BigInteger("1000");

      // assign the max value of bi1, bi2 to bi3
      bi3 = bi1.max(bi2);

      String str = "Maximum Value among " + bi1 + " and "+ bi2+" is "+ bi3;

      // print the maximum value
      System.out.println( str );
   }
}

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

Maximum Value among 123 and 1000 is 1000
java_math_biginteger.htm
广告
© . All rights reserved.