[上]JAVA学习系列199.学生管理系统项目_修改功能
[上]JAVA学习系列199.学生管理系统项目_修改功能
2024-06-14 1 评论 0 阅读 0 点赞

[上]JAVA学习系列199.学生管理系统项目_修改功能

daimafengzi
2024-06-14 / 1 评论 / 0 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2024年06月14日,已超过750天没有更新,若内容或图片失效,请留言反馈。

[上]JAVA学习系列199.学生管理系统项目_修改功能

视频

笔记

3.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("修改成功!!!");
    }
0

评论 (1)

取消
  1. 头像
    daimafengzi
    Linux · Google Chrome

    Warning: Trying to access array offset on value of type null in /app/luoweihua.cn/usr/themes/Joe/core/function.php on line 261
    @

    hello

    回复