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("山海經(jīng)");
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?!=?"山海經(jīng)"){
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?"山海經(jīng)":
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("山海經(jīng)");
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
提交
取消