早教吧作业答案频道 -->其他-->
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循环的原理是啥,看不懂他的原理,感觉很简洁很牛
主要请讲下设计思路
代码如下
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复利求和的算法代码如下...的网友还看了以下:
1.设有变量定义inti,j;与表达式i==0&&j==0等价的表达式是:()(A)i==j(B) 2020-05-14 …
填空A:()this()English?B:()ajacket.A:()itplease.B:J- 2020-06-06 …
C#考试用!急~混分别来~留下详细过程!83.假设变量x的值为25,要输出x的值,下列正确的语句是 2020-06-14 …
Runtime.getRuntime().exec参数String[]cmd1={"sh","-c 2020-07-17 …
Tony:Goodmorning,Gina.Gina:小题1:Tony:小题2:Gina:I’mOk 2020-10-30 …
Tony:GoodmorningGina.Gina:1.Tony2.Gina:I’mOkThanky 2020-10-30 …
Tony:Goodmorning,Gina.Gina:小题1:Tony小题2:Gina:I’mOk, 2020-10-30 …
howthanksmorningjacketwhat'sitA:Good1.Frank!B;Good 2020-10-30 …
howthanksmorningjacketwhat'sitA:Good1.Frank!B;Good 2020-10-30 …
1.---Hello.What’syourname?---name’sJenny.---I’mTom 2020-10-30 …