设计程序:板砖一天50元。提示用户输入你的现有存款和目标。搬一天,看一次自己的存款数,如果存款数不足目标数,则提示:革命尚未成功,同志仍需努力,继续搬砖。直到存款数>=目标数,就可以不搬砖了。最后输出一共搬了多少天。
public class Test {
public static void main(String[] args) {
//提示
System.out.println("请输入你的现有存款和目标存款,用空格分隔:");
int days = 0; //该兄弟一共搬了多少天砖
//接收用户键盘输入
Scanner scanner = new Scanner(System.in);
//现有金额
int total = scanner.nextInt();
//目标金额
int goal = scanner.nextInt();
//循环实现
while(total<goal){
System.out.println("革命尚未成功,同志仍需努力,继续搬砖!");
total += 50;
days++;
System.out.println("搬砖第:"+days+"天...");
}
System.out.println("兄弟一共搬了-->"+days+"天砖。");
}
}
Math.ceil((goal - total)/50)