Java.math.BigInteger.subtract() 方法



描述

java.math.BigInteger.subtract(BigInteger val) 返回一個 BigInteger,其值為 (this - val)。

宣告

下面是 java.math.BigInteger.subtract() 方法的宣告。

public BigInteger subtract(BigInteger val)

引數

val - 從 BigInteger 中減去的數值

返回值

此方法返回一個 BigInteger 物件,其值為this - val。

異常

不適用

示例

以下示例演示了 math.BigInteger.subtract() 方法的使用。

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("-123");

      // assign difference of bi1 and bi2 to bi3
      bi3 = bi1.subtract(bi2);

      String str = "Subtraction result: " +bi1+ " - " +bi2+ " = " +bi3;

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

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

Subtraction result: 123 - -123 = 246
java_math_biginteger.htm
廣告
© . All rights reserved.