わかりました、非常に初歩的な質問です。ユーザーがアンケートを設計できる CLI アプリを作成しています。最初に質問を入力し、次に選択肢の数と選択肢を入力します。入力を取得するためにスキャナーを使用していますが、何らかの理由で、ユーザーはほとんどのものを入力できますが、質問のテキストは入力できません。以下のコード スニペット。
String title = "";
Question[] questions;
int noOfQuestions = 0;
int[] noOfChoices;
Scanner entry = new Scanner(System.in);
System.out.println("Please enter the title of the survey: ");
title = entry.nextLine();
System.out.println("Please enter the number of questions: ");
noOfQuestions = entry.nextInt();
noOfChoices = new int[noOfQuestions];
questions = new Question[noOfQuestions];
for (int i = 0; i < noOfQuestions; i++) {
questions[i] = new Question();
}
for (int i = 0; i < noOfQuestions; i++) {
System.out.println("Please enter the text of question " + (i + 1) + ": ");
questions[i].questionContent = entry.nextLine();
System.out.println("Please enter the number of choices for question " + (i + 1) + ": ");
questions[i].choices = new String[entry.nextInt()];
for (int j = 0; j < questions[i].choices.length; j++) {
System.out.println("Please enter choice " + (j + 1) + " for question " + (i + 1) + ": ");
questions[i].choices[j] = entry.nextLine();
}
}
ありがとう :)