import java.util.*;public class Retirement{
public static void main(String agrs[]){
//read inputs
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 interstRate=in.nextDouble(); double balance=0;
int years=0;
//update account balance while goal isnot 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.");
}
}
public static void main(String agrs[]){
//read inputs
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 interstRate=in.nextDouble(); double balance=0;
int years=0;
//update account balance while goal isnot 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.");
}
}
解决方案 »
- Jtable中复选框的使用问题(JcheckBox)
- ScheduledExecutorService 的问题,请高手帮忙
- 算法问题,求代码
- 我下了个jexcelapi应该放在哪里?
- applet可以具有滚动条的属性吗?
- 我初学JAVA ,请大家帮我看看这个编译是哪里错了?
- 一个jar包,两个可执行程序的问题(两个带有main的类)
- 谁能帮我做一个类?
- Java窗体关闭(初学者)不知错在哪里求指教
- PrintWriter(OutputStream out, boolean autoFlush) 中的out参数为什么可以传入FileWriter对象
- 字符数组小问题?(关于split)
- 用java在linux上如何判断一个文件是否已经传输完毕?
double interstRate=in.nextDouble(); //这里的变量名是interstRate
double interest=balance*interestRate/100; //而这里用到的变量名interestRate跟上面的不一致
这是什么意思啊
double interest=balance*interestRate/100;
balance+=interest; 改一下变量名哦,就可以运行了。。
Scanner in=new Scanner(System.in); //就是从系统输入,