Java.math.BigInteger.min() 方法



描述

java.math.BigInteger.min(BigInteger val) 返回該 BigInteger 和 val 的最小值。

宣告

以下是 java.math.BigInteger.min() 方法的宣告。

public BigInteger min(BigInteger val)

引數

val - 用於計算最小值的數值。

返回值

此方法返回一個 BigInteger,其值是該 BigInteger 和 val 的較小值。如果它們相等,則可以返回其中任意一個。

異常

示例

以下示例顯示了 math.BigInteger.min() 方法的用法。

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 min value of bi1, bi2 to bi3
      bi3 = bi1.min(bi2);

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

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

讓我們編譯並執行上述程式,這將產生以下結果 −

Minimum Value among 123 and 1000 is 123
java_math_biginteger.htm
廣告
© . All rights reserved.