当下面的代码是真实的,这意味着在第一和最后一个字符匹配的持续循环,直到我退出了代码,如何解决呢?如何停止无限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
他表示说他们从来没有改变过。 –