public class ChapterPractice {public static void main(String[] args){//方法一double i = 100000;int count = 0;//统计次数while(i>50000){i = i - i*0.05;count++;if (i < 50000 ){break;}}while(i < 50000){i -= 1000;count++;if (i < 1000){break;}}System.out.println(count);//方法二double money = 100000;int count1 = 0;while(true){if (money > 50000){money *= 0.95;count1++;}else if (money >= 1000){money -= 1000;count1++;}else{break;}}System.out.println(count1);} }
运行结果