不要被阶乘吓到
来源:互联网 发布:淘宝金融 编辑:程序博客网 时间:2024/04/27 16:31
实现代码:
public class numOf0 { public static void main(String[] args) { int n = 100; System.out.println(countOf0(n)); } // 解法1 private static int countOf0(int n) { // TODO Auto-generated method stub int result = 0; for (int i = 1; i <= n; i++) { int j = i; while (j % 5 == 0) { result++; j /= 5; } } return result; } // 解法2 private static int countOf01(int n) { // TODO Auto-generated method stub int result = 0; while (n != 0) { n = n / 5; result = result + n/5; } return result; }}
测试结果:
public class LowestOne { public static void main(String[] args) { // TODO Auto-generated method stub int n = 4; System.out.println(LowestOne(n)); } private static int LowestOne(int n) { // TODO Auto-generated method stub int result = 0; while (n != 0) { n = n >> 1; result = result + n; } return result + 1; }}
测试结果:
0 0
- 不要被阶乘吓到
- 不要被阶乘吓到
- 不要被阶乘吓到
- 不要被阶乘吓到
- 不要被阶乘吓到
- 编程之美2.2 不要被阶乘吓到
- 编程之美 2.2 不要被阶乘吓到
- [编程之美2.2]不要被阶乘吓到
- 编程之美-不要被阶乘吓到
- 不要被阶乘吓到(beauty of programe)
- 编程之美2.2 不要被阶乘吓到
- 【编程之美】2.2不要被阶乘吓到
- 编程之美-不要被阶乘吓到
- 代码 编程之美 P121 2.2不要被阶乘吓到
- 编程之美: 第二章 数字之魅 2.2不要被阶乘吓到
- 不要被阶乘吓倒
- 不要被阶乘吓倒
- 不要被阶乘吓倒
- Hibernate session的方法全集
- windows下使用RedisCluster集群简单实例
- break,continue,break的用法与区别
- CocoaPods 安装和使用
- C#获取进程的主窗口句柄
- 不要被阶乘吓到
- MYSQL DUMP
- requireGestureRecognizerToFail 手势识别
- 数学公式
- 语音播放实例研究
- R语言制作词云
- Scala读取*.properties配置文件
- 一些通用的函数实现
- Tomcat5.5配置-多域名绑定和虚拟目录