求1000!的结果中包含多少个0?注:1000! = 1×2×3×4×5×...×999×1000(求阶乘)
2015-05-28 12:24
344 查看
求1000!的结果中包含多少个0?注:1000! = 1×2×3×4×5×...×999×1000(求阶乘)
package yang.base; import java.math.BigInteger; import java.util.Arrays; import java.util.Scanner; public class Test33 { public static void main(String[] args) { //定义开始时间 long start= System.currentTimeMillis(); //创建开始对象初值为1 BigInteger bi = new BigInteger("1"); // 创建结束对象初值为1000 BigInteger bi2 = new BigInteger("1000"); // 创建求和对象 BigInteger sum = new BigInteger("1"); // 记录个数 int count = 0; // 求出1-1000的阶乘 for (int x = bi.intValue(); x <= bi2.intValue(); x++) { // 使用BigInteger中的valueOf方法把整数类型的数据转换成BigInteger类型的数据,并相乘 sum = sum.multiply(BigInteger.valueOf(x)); } //先把这个结果转换成string类型 String s= sum.toString(); //再使用string类型转换成char类型 char[] result=s.toCharArray(); //统计个数 for(int x=0;x<result.length;x++){ if(result[x]=='0'){ count++; } } System.out.println("1--1000的阶乘中一共有:"+count+"个零"); long end=System.currentTimeMillis(); System.out.println("共耗时:"+(end-start)); } }
相关文章推荐
- 求1000!的结果中包含多少个0?注:1000! = 1×2×3×4×5×...×999×1000
- 黑马程序员—求1000!的结果末尾有多少个0 1000! = 1×2×3×4×5×...×999×1000
- 在1×2×3×...×100的积中,从右边数第25个数字是几
- 1×2×3+2×3×4+4×5×6+...+28×29×30的算法
- 数据关系是1×2×2×12(C)
- Java练习题-求1000!的结果中包含多少个0
- 求1000!的结果中包含多少个0
- CodeWars 给定数值的阶乘结果中包含多少0
- 黑马程序员——解题笔记(1)——求1000!的结果中包含多少个0
- 黑马程序员——求1000!的结果中包含多少个0
- 、求1000!的结果中包含多少个0?注:1000! = 1×2×3×4×5×...×999×1000 *
- 1000!的结果中如果用十进制表示,有多少位
- 1000的阶乘有多少位------log求和方法
- hdu 1124 Factorial 数论,就是求一个数的阶乘的结果末尾有多少0.
- 求1000的阶乘结果尾部0的个数
- n的阶乘结果中末尾有多少个零?
- 1000的阶乘有多少位
- 阶乘结果末尾有多少零?
- 人生·工作的结果 = 思维方式 × 热情 × 能力
- 求1000的阶乘结果尾部0的个数