In Java why pass in a parameter, the parameter in a method to get the right change, but after calling this method in the main method of the parameter is not changed?
My code:
public void RSort123(Student[] stu) {
int k = 0;
Student[] stu1 = new Student[this.len];
for (int i = 0; i < this.len; i++)
stu1[i] = new Student();
Clear(array);
for (int i = 0; i <= 100; i++) {
for (int j = 0; j < this.len; j++) {
if (stu[j].english == i) {
array[i][k++] = j;
}
}
k = 0;
}// 分配
for (int i = 100, j = 0; i >= 0; i--) {
for (int l = 0; array[i][l] != -1; l++) {
stu1[j] = stu[array[i][l]];
j++;
}
}// 收集
stu = stu1;
System.out.println("---------------stu----------------");
for (int p = 0; p < len; p++)
stu[p].display();
System.out.println("---------------stu1---------------");
for (int p = 0; p < len; p++)
stu1[p].display();
System.out.println("---------------end----------------");
}
Code Part of the main code
//Call the method. But not work, But in RSort123() method stu changed. Why?
rs.RSort123(stu);
System.out.println("姓名\t语文\t数学\t英语\t总分");
for(int i=0; i<length; i++){
stu[i].display();
}