package studentmanagement; import java.util.Scanner; public class Books { public static void main(String[] args) { int [] arr1 = new int[5]; String arr2[] = new String[5]; double [] arr3 = new double[5]; Scanner sca = new Scanner(System.in); int i ; int count = 0; while(true){ System.out.println("欢迎来到图书管理系统"); System.out.println("1.添加图书信息"); System.out.println("2.修改图书信息"); System.out.println("3.删除图书"); // System.out.println("4.查询"); System.out.println("5.退出"); int book = sca.nextInt(); if(book == 1){ System.out.println("添加图书"); System.out.print("--输入图书编号"); arr1[count] = sca.nextInt(); System.out.print("--输入书籍名"); arr2[count] = sca.next(); System.out.print("--输入图书价格(单位元)"); arr3[count] = sca.nextDouble(); System.out.println("成功添加"); count ++; for(int j = 0;j <count;j++){ if(arr1[j]==0){ break; } System.out.println("已经添加编码为:"+arr1[j]+" 书籍名称名称为: "+arr2[j]+" 图书价格:"+arr3[j]+"元"); } }else if(book == 2){ System.out.println("修改图书"); System.out.print("选择要修改的图书编号:"); int upId = sca.nextInt(); for(int ii = 0; ii < arr1.length; ii ++) {//1ii=0 i<1 i++ if(upId == arr1[ii]) { System.out.print("--输入图书名"); arr2[ii] = sca.next(); System.out.print("--输入图书价格"); arr3[ii] = sca.nextDouble(); System.out.println("成功修改"); } } for(int j = 0;j <5;j++){ if(arr1[j]==0){ break; } System.out.println("修改后的图书是:"+arr1[j]+" 图书名称为: "+arr2[j]+" 图书价格:"+arr3[j]); } }else if(book == 3){ System.out.println("删除图书"); System.out.print("选择要删除的图书编号:"); int upId = sca.nextInt(); for(int k = 0;k < arr1.length;k ++) { if(upId == arr1[k]) { for(int g = k;g < arr1.length-1;g ++) { arr1[g] = arr1[g + 1]; } } } // arr1[upId-1] = 0; // arr2[upId-1] = null; // arr3[upId-1] = 0.0; for(int j = 0;j <5;j++){ if(arr1[j]==0){ break; } } }else if(book == 5){ System.out.println("退出系统"); return; } } } }