我的项目需要你的帮助。我正在编写一个程序,该程序向学生显示用户之前填写的信息。这是关于我学到了多少方法。我已经写了一个没有方法的程序。但是当我用我遇到的通过引用传递的方法编写相同的东西时......我正在填充 0. 索引但是当我填充 1. 索引时,0. 索引变为空。我尝试了所有方法,但我无法解决这个问题,我认为这与我的回报有关...这里的代码基本上可以帮助我,因为您可以看到我的 Java 语言水平是初学者:);
//=========================================================== Methods
public static void record(String x, int y)
String[] stringArray = new String[100];
stringArray[y] = x;
return stringArray;
}
public static double[] record(double x, int y){
double[] doubleArray = new double[100];
doubleArray[y] = x;
return doubleArray;
}
和我的选择;
case 1: {
System.out.println("** Recording a new student");
System.out.println("*** Please use lower case");
in.nextLine(); // for solve skipping
System.out.print("Enter Student Name and Surname: ");
String namex = in.nextLine();
name=record(namex,accountNumber);
System.out.print("Enter Student Gender(m/f): ");
String genderx = in.nextLine();
gender=record(genderx,accountNumber);
System.out.print("Enter Student Number: ");
String studentNox = in.nextLine();
studentNo=record(studentNox,accountNumber);
System.out.print("Enter Student GPA: "); // i dont use method here for testing
gpa[accountNumber] = in.nextDouble();
accountNumber++;
System.out.println("New Student Recorded. There are ["+accountNumber+"] students in system.");
System.out.println("");
}break;