Java-math-biginteger-max

提供:Dev Guides
移動先:案内検索

Java.math.BigInteger.max()メソッド

説明

  • java.math.BigInteger.max(BigInteger val)*は、このBigIntegerとvalの最大値を返します。

宣言

以下は* java.math.BigInteger.max()*メソッドの宣言です。

public BigInteger max(BigInteger val)

パラメーター

*val* -最大値が計算される値

戻り値

このメソッドは、thisとvalの値が大きいBigIntegerを返します。 それらが等しい場合、どちらかが返されます。

例外

NA

次の例は、math.BigInteger.max()メソッドの使用法を示しています。

package com.finddevguides;

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