1 package demo04; 2 3 import java.math.BigInteger; 4 5 //超过long型的整数, 封装成BigInteger类型的对象 6 public class BigIntegerDemo { 7 public static void main(String[] args) { 8 //构造方法 9 BigInteger b = new BigInteger("11111111111111111111111111111111111111111111"); 10 System.out.println(b); 11 12 BigInteger b1 = new BigInteger("111111111111111111111111"); 13 BigInteger b2 = new BigInteger("222222222222222222222222"); 14 15 //加 16 BigInteger bigadd = b1.add(b2); 17 System.out.println(bigadd); 18 19 //减 20 BigInteger bigsub = b2.subtract(b1); 21 System.out.println(bigsub); 22 23 //乘 24 BigInteger bigmul = b1.multiply(b2); 25 System.out.println(bigmul); 26 27 //除 28 BigInteger bigdiv = b2.divide(b1); 29 System.out.println(bigdiv); 30 31 } 32 }
时间: 2024-10-11 17:49:35