From 75d3e69bc802476a1d3e8c80af77024889c7f5f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=99=E8=8B=8F=E6=96=87?= <2361635242@qq.com> Date: Sun, 25 Dec 2022 12:51:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...40\345\244\247\344\275\234\344\270\232.md" | 182 ++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 "16 \351\230\231\350\213\217\346\226\207/20221225 java\346\226\271\346\263\225\345\244\215\344\271\240\345\244\247\344\275\234\344\270\232.md" diff --git "a/16 \351\230\231\350\213\217\346\226\207/20221225 java\346\226\271\346\263\225\345\244\215\344\271\240\345\244\247\344\275\234\344\270\232.md" "b/16 \351\230\231\350\213\217\346\226\207/20221225 java\346\226\271\346\263\225\345\244\215\344\271\240\345\244\247\344\275\234\344\270\232.md" new file mode 100644 index 0000000..5292c37 --- /dev/null +++ "b/16 \351\230\231\350\213\217\346\226\207/20221225 java\346\226\271\346\263\225\345\244\215\344\271\240\345\244\247\344\275\234\344\270\232.md" @@ -0,0 +1,182 @@ +# 作业 + + + +```java +import java.util.Scanner; + +public class D1 { + + //放外面,让大家共享 + static String[] book =new String[10]; + static Scanner cs=new Scanner(System.in); + public static void main(String[] args) { + + book[0]="《钢铁是怎样炼成的》"; + book[1]="《Offer来了》"; + book[2]="《java从入门到精通》"; + book[3]="《java入门》"; + book[4]="《Java基础》"; + while (true){ + start(); + int aa =top(choice(),book); + if (aa>0) { + break; + } + } + + + } + //启动系统,菜单 + public static void start(){ + System.out.println("==============================\n" + + "- 欢迎使用2班书本管理系统 -\n" + + "- \t\t1.浏览所有书本信息\t\t- \n" + + "- \t\t2.添加书本信息\t\t- \n" + + "- \t\t3.修改书本信息\t\t- \n" + + "- \t\t4.删除书本信息\t\t- \n" + + "- \t\t5.查询书本信息\t\t- \n" + + "- \t\t6.退出书本系统\t\t- \n" + + "=============================="); + } + + //选择菜单的功能 + public static int choice(){ + System.out.println("请选择你的操作:"); + Scanner cs=new Scanner(System.in); + int num = cs.nextInt(); + return num; + } + + //根据选择的数字,使用不同的功能 + public static int top(int num,String[] browse){ + int aa=0; + switch (num){ + case 1: + //System.out.println("1.浏览所以书本信息"); + yillsysbxx(browse); + break; + case 2: + //System.out.println("2.添加书本信息"); + tjsbxx(browse); + break; + case 3: + //System.out.println("3.修改书本信息"); + xgsbxx(browse); + break; + case 4: + //System.out.println("4.删除书本信息"); + scsbxx(browse); + break; + case 5: + //System.out.println("5.查询书本信息"); + cxsbxx(browse); + break; + case 6: + //System.out.println("6.退出书本系统"); + + System.out.println("你选择退出书本系统,再见!"); + aa =1; + break; + } + return aa; + } + + //功能5 + private static void cxsbxx(String[] browse) { + System.out.println("请输入你要查询的书本信息"); + String naem = cs.next(); + int index =searchArr(browse,naem); + if (index==-1){ + System.out.println("查无此书"); + }else{ + System.out.println("此书在第"+(index+1)+"个!"); + } + } + + //功能4 + private static void scsbxx(String[] browse) { + System.out.println("请请输入你要删除的书本信息:"); + String name= cs.next(); + int index =searchArr(browse,name); + if (index==-1){ + System.out.println("无法删除,没有这个书"); + }else{ + browse[index]=null; + System.out.println("删除成功!"); + + } + } + + + //功能3 + private static void xgsbxx(String[] browse) { + System.out.println("请输入你要修改的书本名称"); + String name = cs.next(); + int index = searchArr(browse,name); + System.out.println(index); + if (index==-1){ + System.out.println("对不起没有找到这本书!"); + }else { + System.out.println("请输入新的书名:"); + String newName = cs.next(); + browse[index]=newName; + System.out.println("修改成功!"); + } + } + + //功能2 + public static void tjsbxx(String[] browse) { + System.out.println("请输入你要添加的书本名称"); + String name= cs.next(); + int a=searchArr(browse,name); + if (a==-1){ + int index =searchArr(browse,null); + browse[index]=name; + System.out.println("添加成功!"); + }else { + System.out.println("已经存在"+name+"请不要重新添加!"); + } + + } + + + //功能1 + private static void yillsysbxx(String[] browse) { + int counnt =0; + System.out.println("现在有以下书本:"); + for (String name:browse){ + counnt++; + if (name==null){ + continue; + } + System.out.println(name+"\t"); + } + System.out.println(); + } + + //方法 + public static int searchArr(String[] browse, String name){ + int index = -1; + if (name==null){ + for (int i = 0; i < browse.length; i++) { + if (browse[i]==null){ + index=i; + break; + } + } + }else { + for (int i=0;i