/**
* 10、 小明的妈妈每天会给他20元零花钱。平日里,小明先花掉一半,再把一半存起来。每到周日,小明拿到钱后会把所有零花钱花掉一半。请编程计算,从周一开始,小明需要多少天才能存够100元?
* @author Administrator
*/
- public class Test10 {
- public static void main(String[] args) {
- int money =0;
- int day=1;//从第一天开始
-
- while(money<100){
-
- //周日那20元加在平时攒的钱里面一起花一半
- if(day%7==0){
- money = (money+20)/2;
- System.out.println("本周小明" + day + "天后可存够" + money +"元");
- }else{
- //平时存的钱
- money += 10;
- System.out.println(day + "天后可存够" + money +"元");
- }
- day++;
-
- }
- System.out.println("小明" + (day-1) + "天后可存够" + money +"元钱");
- }
- }
复制代码
|
|