黑马程序员—求1000!的结果末尾有多少个0 1000! = 1×2×3×4×5×...×999×1000

来源:互联网 发布:闲鱼卖家淘宝介入 编辑:程序博客网 时间:2024/05/22 09:01

------- <a href="http://www.itheima.com" target="blank">android培训</a>、<a href="http://www.itheima.com" target="blank">java培训</a>、期待与您交流! ----------

package two;
public class test {


    private static int max = 1000;


    public static int getFactor(int m)
    {
        int count = 0;


    while(m%5 == 0)
    {
        count++;
        if(m >= 5)
        {
        m = m / 5;
        }
    }


    return count;   
    } 


    public static int getNumber()
    {
        int count_5 = 0;


        for(int i = 1;i<=max;i++)
        {
            count_5 += getFactor(i);
        }


        return count_5;
    }
    public static void main(String[] args)
    {
         System.out.println("1*2*...*1000 有 "+test.getNumber()+"个0");
    }
}

------- <a href="http://www.itheima.com" target="blank">android培训</a>、<a href="http://www.itheima.com" target="blank">java培训</a>、期待与您交流! ----------

0 0
原创粉丝点击