package com.itheima;
/**9、 求1000!的结果中包含多少个0?注:1000! = 1×2×3×4×5×...×999×1000*/
import java.math.BigInteger;
public class Test9 {
public static void main(String[] args) {
int lastNum=1000;
BigInteger res = new BigInteger("1");
for(int i=1;i<=lastNum;i++) {
res = res.multiply(new BigInteger(String.valueOf(i)));
}
String s=res.toString();
System.out.println(lastNum+"!的结果是:");
System.out.println(s);
int count=0;
for (int i = 0; i < s.length(); i++) {
if(s.charAt(i)=='0') count++;
}
System.out.println("结果中共有"+count+"个0");
}
} |
|