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++;
}
}
}