package?com.imooc;
import?java.util.*;
public?class?Return?{
public?static?void?main(String[]?args)?{
//?TODO?Auto-generated?method?stub
String[]?book={"數學分析","高等代數","數理統計","回歸分析","多元統計","時間序列","隨機過程"};
int[]?num={1,2,3,4,5,6,7};
Return?cw=new?Return();
System.out.println("輸入命令:1-按照名稱查找圖書;2-按照序號查找圖書");
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("命令輸入錯誤!請根據提示輸入數字命令");
continue;
}
}
if(xz.equals("1")){
System.out.println("請輸入圖書名稱");
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("圖書不存在!請重新輸入");
continue;
}
}
}else?if(xz.equals("2")){
while(true){
System.out.println("請輸入圖書序號:");
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("命令輸入錯誤!請根據提示輸入數字命令");
continue;
}
}
}
}
}
添加回答
舉報
0/150
提交
取消