、求1000!的结果中包含多少个0?注:1000! = 1×2×3×4×5×...×999×1000 *
2015-09-02 15:19
239 查看
public class Test9 {
public static void main(String[] args) {
System.out.println("1000!中包含" + getZeroCount(1000) + "个0");
}
public static int getZeroCount(int num) {
int count = 0; // 定义计数器
for (int i = 5; i <= num; i += 5) { // 由于计算0的个数只和5的数量有关,故每次i递增5
int temp = i;
while (temp % 5 == 0) { // 计算该数的质因数5的个数
count++;
temp = temp / 5;
}
}
return count; // 返回值
}
}
小明的妈妈每天会给他20元零花钱。平日里,小明先花掉一半,再把一半存起来。每到周日,小明拿到钱后会把所有零花钱花掉一半。请编程计算,从周一开始,小明需要多少天才能存够100元?
* @
public class Test10{
public static void main(String[] args) {
long Zong0HQ = 0; //零花钱总数
int day = 0; //总天数
int flag = 0; //星期几
while(Zong0HQ < 100) {
if(Zong0HQ + 10 < 100) {
if(flag == 6 ) {
Zong0HQ = (Zong0HQ + 10) / 2;
flag = 0;
} else {
Zong0HQ += 10;
flag++;
}
} else {
Zong0HQ += 10;
flag++;
}
System.out.println(day + ": " + Zong0HQ);
if(Zong0HQ < 100) day++;
}
}
}
public static void main(String[] args) {
System.out.println("1000!中包含" + getZeroCount(1000) + "个0");
}
public static int getZeroCount(int num) {
int count = 0; // 定义计数器
for (int i = 5; i <= num; i += 5) { // 由于计算0的个数只和5的数量有关,故每次i递增5
int temp = i;
while (temp % 5 == 0) { // 计算该数的质因数5的个数
count++;
temp = temp / 5;
}
}
return count; // 返回值
}
}
小明的妈妈每天会给他20元零花钱。平日里,小明先花掉一半,再把一半存起来。每到周日,小明拿到钱后会把所有零花钱花掉一半。请编程计算,从周一开始,小明需要多少天才能存够100元?
* @
public class Test10{
public static void main(String[] args) {
long Zong0HQ = 0; //零花钱总数
int day = 0; //总天数
int flag = 0; //星期几
while(Zong0HQ < 100) {
if(Zong0HQ + 10 < 100) {
if(flag == 6 ) {
Zong0HQ = (Zong0HQ + 10) / 2;
flag = 0;
} else {
Zong0HQ += 10;
flag++;
}
} else {
Zong0HQ += 10;
flag++;
}
System.out.println(day + ": " + Zong0HQ);
if(Zong0HQ < 100) day++;
}
}
}
相关文章推荐
- Unity 2D游戏开发教程之使用脚本实现游戏逻辑
- 正则匹配常用案例
- 8.11.2 Table Locking Issues 表锁发生
- 链家旗下自如某站一个有意思的文件包含到简单内网渗透(本地文件包含getshell技巧)
- android中判断service是否运行
- databus编译: Execution failed for task ':databus-core:databus-core-impl:compileJava'.
- J2EE、J2SE、J2ME、JDK各个击破(概念级)
- 增加<em>标签
- 数据结构中常见的树(BST二叉搜索树、AVL平衡二叉树、RBT红黑树、B-树、B+树、B*树)
- Spark 下操作 HBase(1.0.0 新 API)
- 判断是不是中文
- Java 字符串和时间互相转化 +时间戳
- 奇葩继承
- 暴跌之后-如何低位灵活补仓
- .vimrc设置说明
- BigDecimal代替浮点数精确计算用法简介
- 关于PADS Layout中焊盘与相同网络覆铜无法连接的解决办法
- C++之tinyXML使用
- sublime text3添加到右键选项
- AVL树(考研的同学需要注意其定义)的判定(某公司2012年校园招聘笔试题目)