亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

只用到簡單的循環,請大佬多多指教

package?com.imooc;
import?java.util.Scanner;
public?class?TestException?{
public?int?read()?{
int?choose?=?0;
try?{
System.out.println("輸入命令:1-按照名稱查找圖書;2-按照序號查找圖書");
Scanner?in?=?new?Scanner(System.in);
choose?=?in.nextInt();
}?catch?(Exception?e)?{
System.out.println("命令輸入錯誤!請根據提示輸入數字命令!");
}
return?choose;
}
public?int?readBookNum()?{
int?num?=?0;
try?{
System.out.println("輸入圖書序號:");
Scanner?in?=?new?Scanner(System.in);
num?=?in.nextInt();
}?catch?(Exception?e)?{
System.out.println("命令輸入錯誤!請根據提示輸入數字命令!");
}
return?num;
}
public?static?void?main(String[]?args)?{
//?TODO?Auto-generated?method?stub
String[]?books?=?new?String[]?{?"算法導論",?"數據結構",?"高數"?};
TestException?test1?=?new?TestException();
int?num1;
outer:?while?(true)?{
num1?=?test1.read();
if?(num1?==?1)?{
boolean?flag1?=?false;
Scanner?in?=?new?Scanner(System.in);
System.out.println("輸入圖書名稱:");
String?name?=?in.nextLine();
inner:?for?(int?j?=?0;?j?<?books.length;?j++)?{
if?(books[j].equals(name))?{
flag1?=?true;
break?inner;
}
}
if?(flag1)?{
System.out.println("book:"?+?name);
break?outer;
}?else?{
System.out.println("圖書不存在!");
}
}?else?if?(num1?==?2)?{
boolean?flag2?=?false;
int?num?=?test1.readBookNum();
inner:?for?(int?i?=?0;?i?<?books.length;?i++)?{
if?(num?==?i)?{
flag2?=?true;
break?inner;
}
}
if?(flag2)?{
System.out.println("book:"?+?books[num]);
break?outer;
}?else?{
System.out.println("圖書不存在!");
}
}
}
}
}


正在回答

1 回答

你是大哥

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

只用到簡單的循環,請大佬多多指教

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號