我是 Java 编程的初学者,我不知道如何解决这个问题:
“创建一个投资应用程序,计算如果每年以 7.5% 的复利计算,2,500 美元的投资需要多少年才能达到至少 5,000 美元的价值”
我尝试使用 for 循环和 do-while 循环来尝试解决问题,但它不起作用。请帮忙!
这是我到目前为止尝试一切之后所拥有的:
/*Investment.java
*This program determines how many years it would take for $2500 to turn into $5000 if
*compounded at 7.5% annually.
*Date: October 27th, 2012
*/
/**
* The following application calculates how many years it will take for $2500 to
* turn into $5000 if compounded at 7.5% annually.
*/
public class Investment {
public static void main(String[] args) {
final int MAX_AMOUNT = 5000;
int investment = 2500;
double interest = 0.075;
double totalValue;
do {
totalValue = (investment + (investment * interest));
} while (totalValue < MAX_AMOUNT);
System.out.println(totalValue);
}
}
帮助将不胜感激!
谢谢,