package?com.imooc;
import?java.util.*;
public?class?Return?{
public?static?void?main(String[]?args)?{
//?TODO?Auto-generated?method?stub
String[]?book={"數(shù)學(xué)分析","高等代數(shù)","數(shù)理統(tǒng)計(jì)","回歸分析","多元統(tǒng)計(jì)","時(shí)間序列","隨機(jī)過程"};
int[]?num={1,2,3,4,5,6,7};
Return?cw=new?Return();
System.out.println("輸入命令:1-按照名稱查找圖書;2-按照序號(hào)查找圖書");
Scanner?input=new?Scanner(System.in);
String?xz;
int?xh;
while(true)
{ xz=input.next();
try{
int?pd=Integer.parseInt(xz);
if?(pd!=1&&pd!=2){
RuntimeException?a=new?RuntimeException();
throw?a;
}
//System.out.println("輸入正確了");
break;
}catch(RuntimeException?e){
System.out.println("命令輸入錯(cuò)誤!請(qǐng)根據(jù)提示輸入數(shù)字命令");
continue;
}
}
if(xz.equals("1")){
System.out.println("請(qǐng)輸入圖書名稱");
while(true){
String?sm=input.next();
//System.out.println("剛才輸入的是"+sm);
try{
for?(int?i=0;i<book.length;i++){
if(sm.equals(book[i])){
System.out.println("find?book:"+book[i]);
break;
}else?
if?(i<6)
continue;
else?if(i==6)
{
//cw.zbds();
RuntimeException?e=new?RuntimeException();
throw?e;
}
}
break;
}catch(RuntimeException?e){
System.out.println("圖書不存在!請(qǐng)重新輸入");
continue;
}
}
}else?if(xz.equals("2")){
while(true){
System.out.println("請(qǐng)輸入圖書序號(hào):");
try{
xh=input.nextInt();
if(xh>=1&&xh<=7){
System.out.println("find?book:"+book[xh-1]);
break;
}else?{
RuntimeException?a=new?RuntimeException();
throw?a;
}
}catch(RuntimeException?a){
System.out.println("命令輸入錯(cuò)誤!請(qǐng)根據(jù)提示輸入數(shù)字命令");
continue;
}
}
}
}
}
異常作業(yè)題目!自己運(yùn)行沒發(fā)現(xiàn)什么問題!希望給點(diǎn)建議
qq_魅影勁_(tái)0
2016-11-18 13:06:48