我收到了无法访问的声明错误。 我知道无法访问通常意味着无意义,但我需要我的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