定义一个成员方法
private static BigInteger factorial1(int a) {
if (a==1){
return new BigInteger("1");//当a=1时返回BigInteger类型的1
}
return new BigInteger(String.valueOf(a)).multiply(jc(a-1));//递归的方法来计算值
}
尝试调用:
BigInteger jc = factorial1(100);
System.out.println(jc);
System.out.println(jc.toString().length());//获取长度
控制台打印数据:
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
158