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);
		
		
		
		
     }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值