import java.util.*;
public class Retirement{
public static void main(String[] args){
Scanner in=new Scanner(System.in);
System.out.print("How much money do you need to retire?");
double goal= in.nextDouble();
System.out.print("How much money will you contribute every year?");
double payment=in.nextDouble();
System.out.print("Interest rate in%:");
double interestRate=in.nextDouble();
double balance=0;
int years=0;
while(balance<goal){
balance+=payment;
double interest=balance*interestRate/100;
balance+=interest;
year++;
}
System.out.println("You can retire in"+years+"years.");
}
}
这是一个简单的Java程序,用于计算达到退休目标所需的年数。用户输入退休所需金额、每年贡献额及利率,程序将输出达到目标所需的年数。
450

被折叠的 条评论
为什么被折叠?



