要求1000的阶乘尾部0的个数,如果想先求出1000的阶乘,肯定超过了基本数据类型的取值范围,此时就需要通过其他途径来解决问题。
1、BigInteger
BigInteger可以接收很大的整数,所以完全可以接收1000的阶乘的结果。
public static void main(String[] args) {
BigInteger bi = new BigInteger("1");
for(int i = 1; i <= 1000; ++i){
bi = bi.multiply(new BigInteger(i + ""));
}
String str = bi.toString();
int count = 0;