/*我需要将一些信息存储在一个参差不齐的二维数组中。所以我希望这个程序能够接受 ex。3个名字,对于每个名字,我希望数组为每个名字存储一些课程。前任。名字安德斯参加了 3 门课程,oop、intP、appDesign。
我试图让它用 2 个 for 循环将此信息处理到数组中,但是循环有问题。希望任何人都可以帮助或给我一个线索。问候
package assignment10;
import java.util.Scanner;
public class NewClass {
public static void main(String[] args) {
System.out.println("Enter the number of students you want to enter into the database");
Scanner number = new Scanner(System.in);
int numberStudents = number.nextInt();
int[] numberOfStudents = new int[numberStudents];
for (int i = 0; i < numberOfStudents.length; i++) {
numberOfStudents[i] = i+1; // here i avoid the length 0
}
System.out.println("you have entered " + numberStudents + " number of students");
for (int j = 0; j < numberOfStudents.length; j++) {
System.out.println(numberOfStudents[j]);
}
// This is here im having trouble Where in the for loops have i made the //mistake
String [][] nameCourseArray =new String [numberOfStudents.length][];
Scanner name = new Scanner(System.in);
Scanner courseName = new Scanner ( System.in);
for( int i = 0 ; i < numberOfStudents.length; i++ ){ // maybe here
System.out.println("enter name of student");
nameCourseArray[0][0] = name.nextLine();
for( int j = 0;j < nameCourseArray[0].length; j++){ // or here
System.out.println("Enter the courseName");
nameCourseArray [i][j] =courseName.nextLine();
}
}
}
}