package com.xesivo;
import java.util.Scanner;
public class MSLibrary {
static int consent1 = 0;
static int consent2 = 0;
static int imput = 0;
public static void methSel() throws Exception{
Scanner in = new Scanner(System.in);
int a = in.nextInt();
if(a != 1){
if(a != 2){
Exception e = new Exception();
throw e;
}
}
imput = a;
consent1 = 1;
}
public static void numSe() throws Exception{
Scanner in = new Scanner(System.in);
int a = in.nextInt();
if(a < 0){
Exception e = new Exception();
throw e;
}
if(a > 8){
Exception e = new Exception();
throw e;
}
for(int i = 1; i <= 8; i++){
if(i == a){
System.out.print("找到图书:");
switch(i){
case 1:
System.out.println("孟子");
break;
case 2:
System.out.println("山海经");
break;
case 3:
System.out.println("说文解字");
break;
case 4:
System.out.println("一生最爱唐诗");
break;
case 5:
System.out.println("一生最爱宋词");
break;
case 6:
System.out.println("丁丁历险记全英");
break;
case 7:
System.out.println("哈利波特全英");
break;
case 8:
System.out.println("英国学生文学读本");
break;
}
}
}
consent2 = 1;
}
public static void nameSe() throws Exception{
Scanner in = new Scanner(System.in);
String a = in.nextLine();
if(a != "孟子"){
if(a != "山海经"){
if(a != "说文解字"){
if(a != "一生最爱唐诗"){
if(a != "一生最爱宋词"){
if(a != "丁丁历险记全英"){
if(a != "哈利波特全英"){
if(a != "英国学生文学读本"){
Exception e = new Exception();
throw e;
}
}
}
}
}
}
}
}
int b = 0;
switch(a){
case "孟子":
b = 1;
break;
case "山海经":
b = 2;
break;
case "说文解字":
b = 3;
break;
case "一生最爱唐诗":
b = 4;
break;
case "一生最爱宋词":
b = 5;
break;
case "丁丁历险记全英":
b = 6;
break;
case "哈利波特全英":
b = 7;
break;
case "英国学生文学读本":
b = 8;
break;
}
for(int i = 1; i <= 8; i++){
if(i == b){
System.out.print("找到图书:");
switch(i){
case 1:
System.out.println("孟子");
break;
case 2:
System.out.println("山海经");
break;
case 3:
System.out.println("说文解字");
break;
case 4:
System.out.println("一生最爱唐诗");
break;
case 5:
System.out.println("一生最爱宋词");
break;
case 6:
System.out.println("丁丁历险记全英");
break;
case 7:
System.out.println("哈利波特全英");
break;
case 8:
System.out.println("英国学生文学读本");
break;
}
}
}
imput = b;
consent2 = 1;
}
public static void main(String[] args) {
System.out.println("欢迎来到小粟图书馆!");
System.out.println("按序号查找图书请按1,按名称查找图书请按2!");
while(consent1 == 0){
try{
methSel();
}catch(Exception e){
System.out.println("输入有误,请重新输入!");
}
}
if(imput == 1){
System.out.println("请输入序号!");
while(consent2 == 0){
try{
numSe();
}catch(Exception e){
System.out.println("输入有误,请重新输入!");
}
}
}
if(imput == 2){
System.out.println("请输入名称!");
while(consent2 == 0){
try{
nameSe();
}catch(Exception e){
System.out.println("输入有误,请重新输入!");
}
}
}
}
}运行结果是这样的嘤嘤嘤为什么?
添加回答
举报
0/150
提交
取消