| 
 
| 复制代码package com.heima;
import java.math.BigInteger;
/*
 * 问题:求1000!的结果中包含多少个0
1000! = 1×2×3×4×5×...×999×1000
遇10为零*/
public class Test2 {
        public static void main(String [] asd)
        {
            BigInteger bt=new BigInteger("1000");
           
            for(int x=1;x<1000;x++)
            {
                    
                    BigInteger aa=new BigInteger(String.valueOf(x));
                    bt=bt.multiply(aa);
            }
            //BigInteger aa=bt.multiply(bt);
            String str=bt.toString();
            System.out.println(str);
            int count=0;
            int dex=0;
            String strr="0";
                    while((dex=str.indexOf(strr,dex))!=-1)
                    {
                            dex++;
                            count++;
                    }                
            System.out.println("零的个数有:"+count);
        }
}
 
 | 
 |