JAVA--封装一类Java对象,计算两个大整数(如123456789123456789123456789和987654321987654321987654321)

import java.math.*;
public class Date {
//3.封装一类Java对象,计算两个大整数(如123456789123456789123456789和987654321987654321987654321)
//的和、差、积和商,并计算一个大整数的因子个数(因子中不包括1和大整数本身)。(选做)
	
	public static void main(String[] args) 
	{
		
				
		BigInteger sum = new BigInteger("0"),
		
		difference = new BigInteger("0"),
				
		product  = new BigInteger("0"),
				
		 quotient = new BigInteger("0"),
		 type1 = new BigInteger("123456789123456789123456789"),
		
		 type2 = new BigInteger("987654321987654321987654321");
		
		sum = type1.add(type2);
		
		difference  = type1.subtract(type2);
		
		product  = type1.multiply(type2);
		
		quotient  = type1.divide(type2);
	
	
		BigInteger i = new BigInteger("0");
		
		BigInteger one = new BigInteger("1");
		
		BigInteger two = new BigInteger("0");
		
		BigInteger yu = new BigInteger("0");
		
		int count =0;
		while(i.compareTo(type1)<=0)
		{
			yu = i.remainder(type1);
			if(yu==two)
			{
				count++;
			}
			i = i.add(one);
		}
	
		System.out.println("两个大整数的和是:"+sum);		
		System.out.println("两个大整数的差是:"+difference);		
		System.out.println("两个大整数的积是:"+product);		
		System.out.println("两个大整数的商是:"+quotient);
		System.out.println("第一个大整数的因子个数为:"+count);
		
		
		
		
     }
}

你可能感兴趣的:(JAVA--封装一类Java对象,计算两个大整数(如123456789123456789123456789和987654321987654321987654321))