首先,我是一个相对较新的程序员,因为它与JAVA有关。我搜索了很多东西,但有可能我没有找到正确的东西。我基本上试图从第一个“年份”到第10个“年份”列出起始金额,乘以百分比,然后加到起始金额。然后,我想要拿出新的金额并一遍又一遍地做同样的事情,直到达到10.或者,即使是指定的总额ex:2000。
public static void main(String[] args)
{
double startAmount = 1000;
double ratePercentage = 0.05;
double newAmount;
for (int i = 0; i <= 10; i++){
newAmount = startAmount + (startAmount * ratePercentage);
System.out.println(i + " " + newAmount);
}
}
答案 0 :(得分:2)
我不能100%确定你想要实现的目标。但假设你正试图做某种复合兴趣。这应该有所帮助。
public static void main(String[] args)
{
double startAmount = 1000;
double ratePercentage = 0.05;
double newAmount;
newAmount = startAmount;
for (int i = 0; i <= 10; i++){
newAmount = newAmount + (newAmount * ratePercentage);
System.out.println(i + " " + newAmount);
}
}
答案 1 :(得分:1)
试试这个
public static void main(String[] args)
{
double startAmount = 1000;
double ratePercentage = 0.05;
double newAmount;
for (int i = 0; i < 10; i++){
newAmount = startAmount + (startAmount * ratePercentage);
System.out.println(i + " " + newAmount);
startAmount=newAmount;
}
}