A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

  1. public class Num
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.                 System.out.println(a(10000));               
  6.         }
  7.         public static int a(int Num)
  8.         {
  9.                 int x = 0;
  10.                 for(int i = 1;i<Num+1;i++)
  11.                 {
  12.                         int count = 0;
  13.                         int a = i;
  14.                         while(i%5 == 0)
  15.                         {        count++;                               
  16.                                 i = i/5;
  17.                         }
  18.                         x+=count;
  19.                         i = a;
  20.                 }
  21.                 return x;               
  22.         }       
  23. }
复制代码

6 个回复

倒序浏览
你这算的只是结尾的0
回复 使用道具 举报
  1. class  quling
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.                 System.out.println(f(10000));
  6.         }
  7.         public static int f(int num)
  8.         {
  9.                 int count=0;
  10.                 for (int x=num; x>9; x=x/10)
  11.                 {
  12.                         if (x%10==0)
  13.                                 count++;       
  14.                 }
  15.                 return count;
  16.         }

  17. }
复制代码
回复 使用道具 举报
原题是统计1000!结果中有多少个0,上面代码统计的是结果末尾有多少连续0
回复 使用道具 举报

这样统计的是10000中有多少0,而不是10000!的结果中有多少0
回复 使用道具 举报
这统计的不是10000!吧
回复 使用道具 举报
careit 发表于 2014-8-28 08:54
这样统计的是10000中有多少0,而不是10000!的结果中有多少0

嗯,看错了。。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马