0
2つの配列の間にどの質問が欠けているのかを私のプログラムで表示したい。私は間違って入力する最初の12のためのすべての正解を入力し、最後の3を入力します。私はそれを表示しようとするたびに、それはいくつかの奇妙な返答が出てくる、私はそれがメモリアドレスかもしれないと思う。私は欠落した質問番号をプリントアウトするためにすべてを試しました。何か助けて頂ければ幸いです。どの質問が配列に欠けているのかを表示
import java.util.Scanner; //import scanner
public class DriverTestBlah {
public static void main(String [] args){
Scanner input = new Scanner(System.in);
char[] correctAnswers = {'A','D','C','A','A','D','B',
'A','C','A','D','C','B','A','B'};
char[] userAnswer = new char[correctAnswers.length];
for(int i = 0; i < 15; i++) //print question numbers/takes user input
{
System.out.print("Question " + (i + 1) + ":");
userAnswer [i] = input.nextLine().charAt(0);
}//end of for loop
for(int i = 0; i < questions.length; i++) //for loop prints you missed
{
System.out.print("You missed question: ");
for(int y = 0; y < 1; y++) //for loop only takes one question # at a time
{
System.out.println(" " + which_questions_missed(userAnswer, correctAnswers));
}//end of question number for loop
}//end of
}//end of main
//create new class that determines which questions missed and returns their numbers
public static int []which_questions_missed(char[] userAnswer, char[] correctAnswers){
int missed[] = new int[correctAnswers.length];
for (int i = 0; i < correctAnswers.length; i++){
if (userAnswer[i] != correctAnswers[i]){
missed[i]=(i+1);//chooses the index of the missed answers and adds 1 to display
}
}
return missed;
}
}//end of class
あなたは配列を印刷しようとしています。 'Arrays.toString(which_questions_missed(userAnswer、correctAnswers))'が必要です。しかし、あなたのアルゴリズムは少し奇妙に見えます。期待している結果が得られていない可能性があります。 – jackgu1988