package com.ithe;
import java.math.BigInteger;
/**
* 求1000!的结果中包含多少个0
1000! = 1×2×3×4×5×...×999×1000
* @author nn
*
*
*/
public class Test9 {
public static void main(String[] args) {
method2();
}
private static void method2() {
BigInteger bI= new BigInteger("1");
for(Integer i=2;i<1001;i++)
{
bI = bI.multiply(new BigInteger(""+i));//multiply是连乘函数
}
String str = bI.toString();//转为字符串以便判断
int count=0;//计算0
for(int j=0;j<str.length();j++)
{
if(str.charAt(j)=='0')
{
count++;
}
}
System.out.println("包含0有:"+count+"个");
}
}
import java.math.BigInteger;
/**
* 求1000!的结果中包含多少个0
1000! = 1×2×3×4×5×...×999×1000
* @author nn
*
*
*/
public class Test9 {
public static void main(String[] args) {
method2();
}
private static void method2() {
BigInteger bI= new BigInteger("1");
for(Integer i=2;i<1001;i++)
{
bI = bI.multiply(new BigInteger(""+i));//multiply是连乘函数
}
String str = bI.toString();//转为字符串以便判断
int count=0;//计算0
for(int j=0;j<str.length();j++)
{
if(str.charAt(j)=='0')
{
count++;
}
}
System.out.println("包含0有:"+count+"个");
}
}