:求1000!的结果中包含多少个0?注:1000! = 1×2×3×4×5×...×999×1000
public static void main(String [] args)
{
int count=1;
for (int x=1;x<=10;x++)
{
count=count*x;
}
String str=String.valueOf( count);
System.out.println("str="+str);
int i=charCount(str);
System.out.println(i);
}
public static int charCount(String str)
{
char [] chs=str.toCharArray();
int count=0;
for (int x=0;x<chs.length;x++)
{
if(chs[x]=='0')
count++;
}
return count;
}
请同学们指教了:) |
|