Java------实现大整数计算

import java.math.BigInteger;

public class BigIntegerDemo{

public static void main(String[] args) {
    BigInteger num3,num4,num5,num6;
    BigInteger num1=new BigInteger("10000000000000000000000000000000");
    //如果对这个大整数进行数学运算?     +-*/
    BigInteger num2=new BigInteger("20000000000000000000000000000000");

    num3=num1.multiply(num2);  //乘法
    System.out.println("两大整数之积为:"+num3);

    num4=num1.add(num2);  //加法
    System.out.println("两大整数之和为:"+num4);

    num5=num1.divide(num2);  //除法
    System.out.println("两大整数之商为:"+num5);

    num6=num1.subtract(num2);   //减法
    System.out.println("两大整数之差为:"+num6);
}

}

点赞