From 94528a9e63d353a9aadc7bbeba300626fd008844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E8=89=AF=E6=B6=9B?= <3159961255@qq.com> Date: Mon, 26 Dec 2022 11:55:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E4=B9=A6=E7=AE=A1=E7=90=86=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...73\347\273\237\344\275\234\344\270\232.md" | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 "20 \347\237\263\350\211\257\346\266\233/20221224 \347\256\241\347\220\206\347\263\273\347\273\237\344\275\234\344\270\232.md" diff --git "a/20 \347\237\263\350\211\257\346\266\233/20221224 \347\256\241\347\220\206\347\263\273\347\273\237\344\275\234\344\270\232.md" "b/20 \347\237\263\350\211\257\346\266\233/20221224 \347\256\241\347\220\206\347\263\273\347\273\237\344\275\234\344\270\232.md" new file mode 100644 index 0000000..3c2f8f3 --- /dev/null +++ "b/20 \347\237\263\350\211\257\346\266\233/20221224 \347\256\241\347\220\206\347\263\273\347\273\237\344\275\234\344\270\232.md" @@ -0,0 +1,121 @@ +## 作业 + +```java +import java.util.Arrays; +import java.util.Scanner; +public class A20 { + + + public static void main(String[] args) { + 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 < arr.length; i++) { + if (want.equals(arr[i])) { + System.out.println("请输入你替换后的书:"); + String newz = scan.next(); + arr[i] = newz; + System.out.println("替换成功!!"); + } + + } + System.out.print(Arrays.toString(arr)); + break; + case 4: + System.out.println(Arrays.toString(arr)); + System.out.println("请输入你想删除的书:"); + String f = sc.next(); + String newArr1[] = new String[arr.length - 1]; + for (int i = 0, k = 0; i < arr.length; i++) { + if (!f.equals(arr[i])) { + newArr1[k] = arr[i]; + k++; + } + } + System.out.println("改变之前的图书信息:" + Arrays.toString(arr)); + System.out.println("改变之后的图书信息 :" + Arrays.toString(newArr1)); + case 5: + System.out.println(Arrays.toString(arr)); + System.out.println("请输入你想要查询的图书信息:"); + String chaxun = sc.next(); + + if (chaxun.equals(arr[0])) { + System.out.println(arr[0]+"这一本书讲的主要是如何从小白提升至大白"); + } + if (chaxun.equals(arr[1])) { + System.out.println(arr[1]+"这一本书讲的主要是如何从小白提升至大佬"); + } + if (chaxun.equals(arr[2])) { + System.out.println(arr[2]+"这一本书讲的主要是如何从小白提升至高手"); + } + if (chaxun.equals(arr[3])) { + System.out.println(arr[3]+"这一本书讲的主要是如何从小白提升至大神"); + } + if (chaxun.equals(arr[4])) { + System.out.println(arr[4]+"这一本书讲的主要是如何从小白提升至神仙"); + } + if (chaxun.equals(arr[5])) { + System.out.println(arr[5]+"这一本书讲的主要是如何从小白提升至宇宙级元老"); + } + if (chaxun.equals(arr[6])) { + System.out.println(arr[6]+"这一本书讲的主要是如何从小白提升至宇宙级元老"); + } + break; + case 6: + System.out.println("已退出图书管理系统"); + break; + } + + } + } + } +``` + + -- Gitee