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.