提交 81050e29 编写于 作者: 邓某人的父亲's avatar 邓某人的父亲

Add new file

上级 b4c3b1a9
import java.util.Scanner;
/**
* This program demonstrates a <code>while</code> loop.
*
* @author Cay Horstmann
* @version 1.20 2004-02-10
* @time 2023/01/11
*/
public class Retirement {
public static void main(String[] args) {
// read inputs
Scanner in = new Scanner(System.in);
System.out.println("How much money do you need to retire? ");
double goal = in.nextDouble();
System.out.println("How much money will you contribute every year? ");
double payment = in.nextDouble();
System.out.println("Interest rate in %: ");
double interestRate = in.nextDouble();
double balance = 0;
int years = 0;
// update account balance while goal isn't reached
while (balance < goal) {
// add this year's payment and interest
balance += payment;
double interest = balance * interestRate / 100;
balance += interest;
years++;
}
System.out.println("You can retire in " + years + " years.");
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册