- Java.math 包额外内容
- Java.math - 枚举
- Java.math - 讨论
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
广告