以下のコードが真の場合、最初と最後の文字が一致すると、コードを終了するまで永遠にループします。あなたのコード内のどこにもループを無限に停止する方法
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;
}
}
}
:その場合は、あなたがもし-else文の外に質問を配置する必要があり、その後、ロジックはこのような何かを行く必要があります。 –
申し訳ありませんが、どういう意味ですか?私はこれに新しいです – impassedKF
彼は彼らが決して変更されないことを意味します。 –