大神幫看看代碼
package borrowbook;
import java.util.Scanner;
/**
?*
?* @author lenovo
?*/
public class BorrowBook {
? ? /**
? ? ?* @param args the command line arguments
? ? ?*/
? ? public static void main(String[] args) {
? ? ? ? // TODO code application logic here
? ? ? ? int[] bookNum= {1,2,3,4};
? ? ? ? String[] bookName={"java","C++","E"};
? ? ? ? System.out.println("請(qǐng)輸入命令:1-按序號(hào)查找圖書(shū);2-按書(shū)名查找圖書(shū)");
? ? ? ? Scanner input=new Scanner(System.in);
? ? ? ? int a;
? ? ? ? try{
? ? ? ? ? ? a=input.nextInt();
? ? ? ? ? ? xunhuan1:
? ? ? ? ? ? if(a==1){
? ? ? ? ? ? ? ? System.out.println("請(qǐng)輸入圖書(shū)序號(hào):");
? ? ? ? ? ? ? ? int num=input.nextInt();
? ? ? ? ? ? ? ? System.out.println("book:"+bookName[num-1]);
? ? ? ? ? ? }else if(a==2){
? ? ? ? ? ? ? ? System.out.println("請(qǐng)輸入書(shū)名:");
? ? ? ? ? ? ? ? String name=input.next();
? ? ? ? ? ? ? ? for(int i=0;i<bookName.length;i++){
? ? ? ? ? ? ? ? ? ? //System.out.println(bookName[i]);
? ? ? ? ? ? ? ? ? ? if(bookName[i].equals(name)){
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("book:"+bookName[i]);
? ? ? ? ? ? ? ? ? ? ? ? break xunhuan1;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? System.out.println("該書(shū)不存在");
? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? System.out.println("請(qǐng)輸入1或2");
? ? ? ? ? ? }
? ? ? ? }catch(Exception e){
? ? ? ? ? ? System.out.println("指令類(lèi)型不正確,請(qǐng)重新輸入");
? ? ? ? }
? ? }
? ??
}
2016-06-19
為什么要用break?????