[上]JAVA%e5%ad%a6%e4%b9%a0%e7%b3%bb%e5%88%97" title="查看更多关于 JAVA学习系列 的文章" target="_blank">JAVA学习系列199.学生管理系统项目_修改功能
视频
笔记
7.修改功能_updateStudent
private void updateStudent() {
//1.录入要修改的学生学号 id
System.out.println("请您输入要修改的学生学号:");
int id = sc.nextInt();
/*
2.注意:修改完之后不能直接将id当成索引去存储新的学生对象
原因:id和学生在数组中的索引不是对应的
解决:根据id查询对应的学生在数组中的索引位置
*/
int updateIndex = ArrayUtils.findIndexById(students,id,count);
System.out.println("请您输入学生姓名:");
String name = sc.next();
System.out.println("请您输入学生年龄:");
int age = sc.nextInt();
System.out.println("请您输入学生性别:");
String sex = sc.next();
Student student = new Student(id, name, age, sex);
students[updateIndex] = student;
System.out.println("修改成功!!!");
}

hello