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.");
   }
}

解决方案 »

  1.   

    拼写错误!
      double   interstRate=in.nextDouble(); //这里的变量名是interstRate
      double   interest=balance*interestRate/100; //而这里用到的变量名interestRate跟上面的不一致
      

  2.   

    Scanner   in=new   Scanner(System.in); 
    这是什么意思啊
      

  3.   

    balance+=payment;
    double   interest=balance*interestRate/100;
    balance+=interest; 改一下变量名哦,就可以运行了。。
    Scanner       in=new       Scanner(System.in);  //就是从系统输入,