在我正在处理的程序中,我创建了一个循环来接收20个单独的字符作为用户输入,转换为char,存储在array2中,并将array2返回到main。当我运行我编写的程序时,似乎我写的代码没有正确地将字符存储在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 2010-11-30 05:03:59