public class PinMoney {
public static void main(String[] args) {
System.out.println("小明需要"+cunqian(1,0)+"天才能存够100元");
}
//方法返回值类型时int型.参数类表int day,int money
public static int cunqian(int day,int money){
//定义一个循环,看是否满足
while (money<100) {
if(day%7!=0){
money+=10;
}else{
money=(money+20)/2;
}
//运算过后再判断是否满足,满足就跳出循环,防止day经再次循环后多加.
if(money>=100){
break;
}
day++;
}
return day;
}
}
|