我收到了無法訪問的聲明錯誤。 我知道無法訪問通常意味着無意義,但我需要我的while循環的isValid語句工作。爲什麼我得到這個錯誤,我該如何解決它?這是我的代碼。此布爾值聲明無法訪問聲明
我得到布爾isValid錯誤;
預先感謝您的任何意見。
public static double calculateMonthlyPayment(double loanAmount, double monthlyInterestRate, int months)
{
double monthlyPayment =
loanAmount * monthlyInterestRate/
(1 - 1/Math.pow(1 + monthlyInterestRate, months));
return monthlyPayment;
boolean isValid;
isValid = false;
//while loop to continue when input is invalid
while (isValid ==false)
{
System.out.print("Continue? y/n: ");
String entry;
entry = sc.next();
if (!entry.equalsIgnoreCase("y") && !entry.equalsIgnoreCase("n"))
{
System.out.println("Error! Entry must be 'y' or 'n'. Try again.\n");
}
else
{
isValid = true;
} // end if
sc.nextLine();
} // end while
double entry = 0;
return entry;
}
塊的執行結束點耶我接受@santhosh +1 :) – Raj 2014-10-10 05:19:44