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函數的用途嗎?它不應該返回一組學生,它應該讀一個學生,並只是返回它。 – PyThon