Java-math-biginteger-multiply

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

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

説明

  • java.math.BigInteger.multiply(BigInteger val)*は、値が(this * val)であるBigIntegerを返します。

宣言

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

public BigInteger multiply(BigInteger val)

パラメーター

*val* -このBigIntegerで乗算される値。

戻り値

このメソッドは、値がthis * valであるBigIntegerオブジェクトを返します。

例外

NA

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

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("7");
      bi2 = new BigInteger("20");

     //multiply bi1 with bi2 and assign result to bi3
      bi3 = bi1.multiply(bi2);

      String str = bi1 + " *" + bi2 + " = " +bi3;

     //print bi3 value
      System.out.println("Multiplication result is " +str);
   }
}

上記のプログラムをコンパイルして実行すると、次の結果が生成されます-

Multiplication result is 7* 20 = 140