ユーザーがNを押すまで、このコードをループする方法。「Continue?[Y/N]」という最初の完了後にプロンプトを表示したい。大文字かどうかは関係ありません。それを行う方法を知っているが、firstLetters.equalsJavaコードをループする方法
package firstLast;
import java.util.Scanner;// Imported Scanner class
public class firstLast {
public static void main(String[] args) {
// Miwand's First Last program
Scanner in = new Scanner(System.in); // Insert Scanner to get input from user later on
String word; // The initial word
System.out.println("Please enter a string longer than 4 letters"); // Asking user to enter string that's more than 4 chars long
word = in.nextLine(); // Getting input from user
for()
String firstLetters = (word.substring(0, 2)); // Getting the first two letters
String lastLetters = (word.substring(word.length() - 2)); // Getting the last two letters
if (firstLetters.equalsIgnoreCase(lastLetters)) // Ignores case and checks if the firstLetters and lastLetters are the same
{
System.out.println("The fist two letters and the last two are the same!"); // If they are than print out this
}
else
{
System.out.println("Different :("); // If they are different, print out this
}
}
}
あなたは、あなたの宿題を手助けするために他の人たちが時間を費やすことを期待しています。しかし、あなたはあなたの質問のすべてを適切にフォーマット/インデントするために3分かかることはありません。 – GhostCat
ヒント:後続のすべてのコメント...実際の使用はほとんどありません。そのようなラインノイズを抑えるために自分自身を鍛えてはいけません。コメントはありません** **コードは何をしていますか? **なぜ** - それがコード自体を読むことから明らかでないときだけコメントします。 – GhostCat
私は、Javaループの例を見つけるのは簡単だから、この質問を議論の対象外としています。たぶんStack Overflowのドキュメントをチェックしてください。 – EJoshuaS