當下面的代碼是真實的,這意味着在第一和最後一個字符匹配的持續循環,直到我退出了代碼,如何解決呢?如何停止無限while循環
while (true) {
// Ignores case and checks if the firstLetters and lastLetters are the same
if (firstLetters.equalsIgnoreCase(lastLetters))
{
// if they are then print out this
System.out.println("The first two letters and the last two are the same!");
}
else
{
System.out.println("Different :("); // If they are different print out this
System.out.println("Continue? [Y/N]");
String ans = in.nextLine();
System.out.println("Please enter a string longer than 4 letters");
word=in.nextLine();
// Ignores case and checks if the firstLetters and lastLetters are the same
if (firstLetters.equalsIgnoreCase(lastLetters))
{
break;
}
}
}
你永遠不更新'firstLetters'和'lastLetters'。 –
對不起,你的意思是?進出口新的這 – impassedKF
他表示說他們從來沒有改變過。 –