2017-01-05 103 views
-8

此代码不起作用。我得到我似乎无法以下错误(在Eclipse)来解决:在Java中打印循环结果

语法错误,插入“:: IdentifierOrNew”完成ReferenceExpression
语法错误,插入“;”完成BlockStatements
重复的局部变量的兴趣

import java.util.Scanner; 

public class DoWhile { 

    public static void main (String[] args) 
    { 
     Scanner in = new Scanner(System.in); 
     System.out.print("balance: "); 
     int balance = in.nextInt(); 
     System.out.print("interestRate: "); 
     double interestRate = in.nextDouble(); 
     System.out.print("year: "); 
     int year = in.nextInt(); 

     System.out.print("input: "); 
     String input = in.next(); 
     Integer interest = null; //to define interest  

     do 
     { 
      double interest = balance * interestRate/100; 
      balance += interest; 
      year++; // print current balance 
     } 
     while (input.equals("N")); 
     System.out.println("interest: " + interest + "balance: " + balance + "year: " + year) ; 
    }; 
} 
+2

如果您的固定缩进它会更容易看出问题。 – khelwood

+0

'interest'必须定义为'Double':'Double interest = null; do { interest = balance * interestRate/100; ' – DimaSan

回答

-1

变量interest声明两次。

这里是你的代码稍微清理版本:

​​
+0

确实,修正了缩进。 – cringe