1 import java.math.BigInteger; 2 3 public class BigInt { 4 BigInteger m1; 5 BigInteger m2; 6 BigInteger m3; 7 8 BigInt(String s1, String s2) { 9 m1 = new BigInteger(s1); 10 m2 = new BigInteger(s2); 11 } 12 13 public void add() { 14 m3 = m1.add(m2); 15 System.out.println("两个数的和为:" + m3); 16 } 17 18 public void cut() { 19 m3 = m1.subtract(m2); 20 System.out.println("两个数的差为:" + m3); 21 } 22 23 public void multiply() { 24 m3 = m1.multiply(m2); 25 System.out.println("两个数的积为:" + m3); 26 } 27 28 public void divide() { 29 m3 = m1.divide(m2); 30 System.out.println("两个数的商为:" + m3); 31 } 32 33 public void factorCount() { 34 int count = 0; 35 for (BigInteger i = BigInteger.valueOf(2); i.compareTo(m1) < 0; i = i 36 .add(BigInteger.ONE)) { 37 if (m1.remainder(i).equals(BigInteger.ZERO)) { 38 ++count; 39 } 40 } 41 System.out.println(m1 + "的因子个数为:" + count); 42 } 43 44 45 public static void main(String[] args) 46 { 47 String num1="123456789123456789123456789"; 48 String num2="987654321987654321987654321"; 49 BigInt bigInt=new BigInt(num1,num2); 50 51 bigInt.add(); 52 bigInt.cut(); 53 bigInt.multiply(); 54 bigInt.divide(); 55 bigInt.factorCount(); 56 } 57 }