-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) ;
};
}
如果您的固定縮進它會更容易看出問題。 – khelwood
'interest'必須定義爲'Double':'Double interest = null; do { interest = balance * interestRate/100; ' – DimaSan