早教吧 育儿知识 作业答案 考试题库 百科 知识分享

java复利求和的算法代码如下Scannerin=newScanner(System.in);System.out.print("Howmuchmoneydoyouneedtoretire?");doublegoal=in.nextDouble();System.out.print("Howmuchmoneywillyoucontributeeveryyear?");doublepayment=in.n

题目详情
java复利求和的算法
代码如下
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)
{
// add this year's payment and interest
balance += payment;
double interest = balance * interestRate / 100;
balance += interest;
years++;
}
下面这个while循环的原理是啥,看不懂他的原理,感觉很简洁很牛
主要请讲下设计思路
▼优质解答
答案和解析
这个balance不是利息,是本息和,复利就是利息不断加到本金里面利滚利
看了java复利求和的算法代码如下...的网友还看了以下: