java二维数组班级系统增删改查
时间: 2023-11-18 16:39:47 浏览: 59
好的,对于班级系统的增删改查可以使用二维数组来实现。具体操作可以参考以下代码:
//创建一个二维数组,模拟班级学生的信息
String[][] students = new String[3][3];
students[0][0] = "张三";
students[0][1] = "男";
students[0][2] = "13";
students[1][0] = "李四";
students[1][1] = "女";
students[1][2] = "14";
students[2][0] = "王五";
students[2][1] = "男";
students[2][2] = "15";
//查询学生信息
System.out.println("查询学生信息:");
for (int i = 0; i < students.length; i++) {
for (int j = 0; j < students[i].length; j++) {
System.out.print(students[i][j] + "\t");
}
System.out.println();
}
//添加学生信息
System.out.println("添加学生信息:");
String[][] newStudents = new String[4][3];
System.arraycopy(students, 0, newStudents, 0, students.length);
newStudents[3][0] = "赵六";
newStudents[3][1] = "女";
newStudents[3][2] = "16";
students = newStudents;
//删除学生信息
System.out.println("删除学生信息:");
String[][] delStudents = new String[2][3];
System.arraycopy(students, 0, delStudents, 0, 2);
System.arraycopy(students, 3, delStudents, 2, 1);
students = delStudents;
//修改学生信息
System.out.println("修改学生信息:");
students[1][0] = "陈七";
students[1][1] = "男";
//查询修改后的学生信息
System.out.println("查询修改后的学生信息:");
for (int i = 0; i < students.length; i++) {
for (int j = 0; j < students[i].length; j++) {
System.out.print(students[i][j] + "\t");
}
System.out.println();
}
阅读全文