ファイルから要素を読み取って解析した後、要素を配列に入れるのに苦労しています。私が読み込んだテキスト ファイルには質問があり、次の行はどの回答が正しいかを示す数字であるという考えです。文字列を解析して int にしますが、解析した int を Answers 配列に追加できません。私の質問は、配列の回答にintを追加するにはどうすればよいですか? これが私のコードです
//here is how I define my arrays
List<String> questions = new ArrayList<String>();
List<String> other = new ArrayList<String>();
int[] answers = new int[questions.size()];
while (fScan.hasNextLine())
{
String line = fScan.nextLine();
if (line.contains("?"))
{
questions.add(line);
String correctAnswer = fScan.nextLine();
int rightAnswer = Integer.parseInt(correctAnswer);
//here's where things go wrong
answers.add(rightAnswer);
}
else
{
other.add(line);
}
}