用用到大整数。
- package test;
- import java.math.BigInteger;
- public class Test8 {
- public static void main(String[] args) {
- getZero(1000);
- }
- public static void getZero(int num) {
- BigInteger bigInteger = BigInteger.valueOf(1);
- for (int i = 1; i <= num; i++) {
- bigInteger = bigInteger.multiply(BigInteger.valueOf(i));
- }
- char[] chars = bigInteger.toString().toCharArray();
- int count = 0;
- for (int i = 0; i < chars.length; i++) {
- if(chars[i]=='0') {
- count++;
- }
- }
- System.out.println(num+"! 含有 "+count+" 个0");
- }
- }
复制代码
|