【发布时间】:2016-06-10 19:06:15
【问题描述】:
public static public static void main(String[] args) {
System.out.print("Enter the number of student names to input: ");
int studentNum = new Scanner(System.in).nextInt();
String students[ ] = new String[studentNum];
for(int i = 0; i<studentNum; i++){
students[ i ] = inputStudent(i+1);
}
}
public static String[] inputStudent(int i) {
String studentNum[] = new String[i];
for(int a=0; a<i; a++) {
System.out.print("Enter student name"+(a+1)+": ");
studentNum[a]=new Scanner(System.in).nextLine();
}
return studentNum;
}
错误:
students[ i ] = inputStudent(i+1);
它说:
incompatible types: String[] cannot be converted to String
PS: 主函数不要修改。
【问题讨论】:
-
你能解释一下 inputStudent 函数的用途吗?它不能返回学生数组,它应该读取一个学生并返回它。
标签: java arrays methods return