题目描述:
某程序员开始工作,年薪N万,他希望在中关村公馆买一套60平米的房子,现在价格是200万,假设房子价格以每年百分之K增长,并且该程序员未来年薪不变,且不吃不喝,不用交税,每年所得N万全都积攒起来,问第几年能够买下这套房子?(第一年年薪N万,房价200万)
代码:
package lanqiao;import java.math.BigInteger;
import java.util.*;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();int lr = sc.nextInt();int sum = 0;double fg = 200;double lrr = lr;
// System.out.println(lrr);boolean flag = false;for(int i = 1;i <= 20;i ++){sum += n;if(sum >= fg){flag = true;System.out.println(i);break;}fg = fg * (1 + lrr / 100);}if(!flag){System.out.println("Impossible");}}
}