题解 | 买房子
买房子
https://www.nowcoder.com/practice/a4b46b53773e4a8db60b5f7629ce03e9
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int earnMoney = in.nextInt();
int increase = in.nextInt();
double price = 200.0;
int year = 0;
for(year = 1;year<=21;year++){
//System.out.println("当前money:"+earnMoney * year+",当前price:"+price);
if(earnMoney * year >= price){
break;
}else{
double multiply = (increase * 1.0)/100 + 1;
price = price * multiply;
}
}
System.out.println(year <= 21 ? year : "Impossible");
}
in.close();
}
}