java.math.BigInteger.subtract(BigInteger val) 返回一個BigInteger,其值是 (this - val).
以下是java.math.BigInteger.subtract()方法的宣告
public BigInteger subtract(BigInteger val)
val - 從當前BigInteger減去的值
此方法返回BigInteger物件的值, this - val .
NA
下面的例子顯示math.BigInteger.subtract()方法的用法
package com.yiibai; 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