From f4311b1764c029465239f9773a2a6f1bb171021a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=BF=8A=E5=85=B4?= <3250103239@qq.com> Date: Sun, 25 Dec 2022 20:58:09 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E5=8D=81=E4=BA=8C=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...41\347\220\206\347\263\273\347\273\237.md" | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 "14 \346\235\216\344\277\212\345\205\264/20221224 \345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.md" diff --git "a/14 \346\235\216\344\277\212\345\205\264/20221224 \345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.md" "b/14 \346\235\216\344\277\212\345\205\264/20221224 \345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.md" new file mode 100644 index 0000000..7fe7fe1 --- /dev/null +++ "b/14 \346\235\216\344\277\212\345\205\264/20221224 \345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.md" @@ -0,0 +1,127 @@ +保存数据 要用到数据库,但是还没有数据库功能 所以先用数组充当 + +### 图书管理系统 + +```java +import java.util.Arrays; +import java.util.Scanner; + +public class M1 { + public static void main(String[] args) { + /*1.浏览所有图书 + 2.添加图书 + 3.替换图书 + 4.删除图书 + 5.查询图书信息 + 6.退出图书管理系统 + */ + while (true){ + System.out.println(""); + String arr[] = {"java入门", "java进阶", "python入门", "python进阶", "c++入门", "c++进阶", "计算机与科学"}; + System.out.println("1.浏览所有图书"+"\n"+"2.添加图书"+"\n"+ "3.替换图书"+"\n"+"4.删除图书"+"\n"+"5.查询图书信息"+"\n"+"6.退出图书管理系统"); + System.out.println("请输入相应数字执行相应操作:"); + Scanner sc = new Scanner(System.in); + int num = sc.nextInt(); + if (num==6){ + break; + } + switch (num){ + case 1: + System.out.println(Arrays.toString(arr)); + break; + case 2: + int count=0; + System.out.println("输出原先数组"); + System.out.println(Arrays.toString(arr)); + System.out.println("请问你想添加几本书?(请输入一个数字:)"); + int num1 = sc.nextInt(); + int num2 = num1; + for (int i = 0; i < num2; i++) { + System.out.println("正在给图书" + (i + 1) + "腾出空间,请稍等"); + count++; + } + System.out.println(count + "次"); + System.out.println("加载完毕"); + String newArr[] = new String[count + arr.length]; + for (int i = 0; i < num1; i++) { + System.out.println("请输入你想加入的" + (i + 1) + "本书:"); + String mk = sc.next(); + newArr[i] = mk; + } + for (int i = 0; i < newArr.length; i++) { + if (i >= count) { + newArr[i] = arr[i - count]; + } + } + System.out.println(Arrays.toString(newArr)); + break; + case 3: + Scanner scan = new Scanner(System.in); + String arr1[] = {"java入门", "java进阶", "python入门", "python进阶", "c++入门", "c++进阶", "计算机与科学"}; + for (String string : arr1) { + + System.out.print(string + " "); + } + System.out.println();//换行 + System.out.println("请输入你想替换的书:"); + String want = scan.next(); + for (int i = 0; i