小编Jet*_*ett的帖子

JAVA-将数组返回到main

在我正在处理的程序中,我创建了一个循环来接收20个单独的字符作为用户输入,转换为char,存储在array2中,并将array2返回到main.当我运行我编写的程序时,似乎我编写的代码没有正确地存储array2中的字符.

主要:

// Create array to hold user's answers, and pass answers to the array.
char array2[ ] = new char[20];
getAnswers(array2);
Run Code Online (Sandbox Code Playgroud)

在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; …
Run Code Online (Sandbox Code Playgroud)

java arrays

2
推荐指数
1
解决办法
493
查看次数

标签 统计

arrays ×1

java ×1