Java中BigInteger上的数学运算
让我们使用Java中的内置方法在BigInteger上应用以下操作。
Addition: add() method Subtraction: subtract() method Multiplication: multiply() method Division: divide() method
让我们创建三个BigInteger对象。
BigInteger one = new BigInteger("98765432123456789");
BigInteger two = new BigInteger("94353687526754387");
BigInteger three = new BigInteger("96489687526737667");对它们应用数学运算。
one = one.add(two);
System.out.println("Addition Operation = " + one);
one = one.multiply(two);
System.out.println("Multiplication Operation = " + one);以下是一个例子-
示例
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
BigInteger one = new BigInteger("98765432123456789");
BigInteger two = new BigInteger("94353687526754387");
BigInteger three = new BigInteger("96489687526737667");
one = one.add(two);
System.out.println("Addition Operation = " + one);
one = one.multiply(two);
System.out.println("Multiplication Operation = " + one);
two = three.subtract(two);
System.out.println("Subtract Operation = " + two);
two = three.divide(two);
System.out.println("Division Operation = " + two);
}
}输出结果
Addition Operation = 193119119650211176 Multiplication Operation = 18221501070917918273532554434429112 Subtract Operation = 2135999999983280 Division Operation = 45
热门推荐
10 诗词送行祝福语大全简短
11 新房开工吉日祝福语简短
12 50多岁生日简短祝福语
13 安徽疫情祝福语简短英语
14 农民朋友发财祝福语简短
15 对生活祝福语简短精辟
16 搬家词简短祝福语朋友
17 女神结婚快乐祝福语简短
18 文学短句祝福语大全简短