特别大的数的阶乘问题,利用BigInteger进行运算

 


我们在进行阶乘运算时,我们会利用阶乘的方法进行运算。但是我们用的大部分是小型的数字,而遇到大的数字时候(如100的阶乘)。我们应该用BigInteger类进行运算具体代码

package cn.javass.di9zhang.test;

import java.math.BigInteger;

public class MyBigInteger {
	public static void main(String[] args) {
		MyBigInteger t = new MyBigInteger();
		BigInteger b = t.t1(BigInteger.valueOf(1000L));
		System.out.println(b);
	}
	
	public BigInteger t1(BigInteger a){
		if(a.equals(BigInteger.valueOf(1L))){
			return BigInteger.valueOf(1L);
		}
		else{
		
			return a.multiply(t1(a.subtract(BigInteger.valueOf(1L))));
		}
	}
}


你可能感兴趣的:(BIgInteger)