视频
笔记
3.4.工具类_ArrayUtils
public class ArrayUtils { private ArrayUtils(){ } public static int findIndexById(Student[] students,int id,int count){ //遍历,查找 for (int i = 0; i < count; i++) { if (id==students[i].getId()){ return i; } } return -1; } }
3.5.添加功能_addStudent
private void addStudent() { //1.键盘录入学生信息 System.out.println("请您输入学生学号:"); int id = sc.nextInt(); System.out.println("请您输入学生姓名:"); String name = sc.next(); System.out.println("请您输入学生年龄:"); int age = sc.nextInt(); System.out.println("请您输入学生性别:"); String sex = sc.next(); //2.将学生信息封装到Student对象中 Student student = new Student(id, name, age, sex); //3.将封装好的Student对象放到students数组中 students[count] = student; //4.count++记录存储了多少个对象 count++; System.out.println("添加成功!!!"); }