用JAVA实现一个简单的电话本管理系统,能存储100个人的姓名、性别、年龄、电话等信息,并能对此系统进行增删改查的操作。 部分代码如下: public class Phbook { public static void main(String[] args) { Person personarray[] = new Person[100]; int index = 0; for (int i = 0; i < 100; i++) { System.out.println("电话本管理系统"); System.out.println("1.添加 2.删除 3.修改 4.查询所有 5.根据姓名查询 0.退出"); System.out.println("请选择业务"); Scanner input = new Scanner(System.in); int a = input.nextInt(); switch (a) { case 0: { System.out.println("退出系统"); i = 101; } ; break; case 1: { System.out.println("添加电话本"); System.out.print("姓名:"); Scanner n = new Scanner(System.in); String name = n.next(); System.out.print("性别:"); Scanner s = new Scanner(System.in); String sex = s.next(); System.out.print("年龄:"); Scanner ag = new Scanner(System.in); String age = ag.next(); System.out.print("电话:"); Scanner tel = new Scanner(System.in); String telnum = tel.next(); System.out.print("qq:"); Scanner q = new Scanner(System.in); String qq = q.next(); System.out.print("地址:"); Scanner add = new Scanner(System.in); String address = add.next(); personarray[index] = new Person(name, sex, age, telnum, qq, address); index = index + 1; } ; break; case 2: { System.out.println("删除电话本"); System.out.println("需要删除的姓名:"); Scanner name0 = new Scanner(System.in); String namedel = name0.next(); for (int j = 0; j < index; j++) { if (namedel.equals(personarray[j].name) == true) { for (int n = j; n < index - 1; n++) { personarray[n] = personarray[n + 1]; } index = index - 1; break; } if (j == index - 1) { System.out.println("查无此人"); } } } ; break; case 3: { System.out.println("修改电话本"); System.out.println("需要修改的姓名:"); Scanner name00 = new Scanner(System.in); String nameedit = name00.next(); for (int k = 0; k < index; k++) { if (nameedit.equals(personarray[k].name) == true) { System.out.print("姓名:"); Scanner xm1 = new Scanner(System.in); String name1 = xm1.next(); System.out.print("性别:"); Scanner xb1 = new Scanner(System.in); String sex1 = xb1.next(); System.out.print("年龄:"); Scanner nl1 = new Scanner(System.in); String age1 = nl1.next(); System.out.print("电话:"); Scanner dh1 = new Scanner(System.in); String telnum1 = dh1.next(); System.out.print("qq:"); Scanner q1 = new Scanner(System.in); String qq1 = q1.next(); System.out.print("地址:"); Scanner dz1 = new Scanner(System.in); String address1 = dz1.next(); personarray[k] = new Person(name1, sex1, age1, telnum1, qq1, address1); break; } if (k == index - 1) { System.out.println("查无此人"); } } } ; break; case 4: { System.out.println("显示所有电话本"); for (int l = 0; l < index; l++) { System.out.println(personarray[l].toString()); } } ; break; case 5: { System.out.println("查询电话本"); System.out.println("需要查询的姓名:"); Scanner na = new Scanner(System.in); String nameprint = na.next(); for (int m = 0; m < index; m++) { if (nameprint.equals(personarray[m].name) == true) { System.out.println(personarray[m].toString()); break; } if (m == index - 1) { System.out.println("查无此人"); } } } ; break; default: { System.out.println("无此功能"); } ; break; } } public Person(String name, String sex, String age, String telnum, String qq, String address) { this.name = name; this.sex = sex; this.age = age; this.telnum = telnum; this.qq = qq; this.address = address; } public String toString() { return " [姓名=" + name + ", 性别=" + sex + ", 年龄=" + age + ", 电话=" + telnum + ",qq=" + qq + ", 地址=" + address + "]"; } 下面是程序运行的结果: