私が取り組んでいるプログラムでは、ユーザー入力として20個の文字を受け取り、charに変換し、array2に格納し、array2をmainに戻すループを作成しました。私が書いたプログラムを走らせたとき、私が書いたコードはchar2をarray2に正しく格納していなかったようだ。メインでJAVA-配列をメインに戻す
:
// Create array to hold user's answers, and pass answers to the array.
char array2[ ] = new char[20];
getAnswers(array2);
getAnswersで():あなたはそれを新しい文字を割り当てるのではなく、入力変数に値を取得した後
// getAnswers method requests user input and passes to array2.
public static char[ ] getAnswers(char array2[ ])
{
String input; // Holds user input.
Scanner keyboard = new Scanner(System.in);
// Request user input.
System.out.println("Enter the answers for the the multiple choice exam.");
// Loop to receive input into array.
for (int index = 0; index < 20; index++)
{
System.out.print("Enter number " + (index + 1) +": ");
input = keyboard.nextLine();
array2 = input.toCharArray();
}
return array2;
}
ああ、持っています。ありがとうございました。 – Jett