大神幫看看代碼
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("請輸入命令:1-按序號查找圖書;2-按書名查找圖書");
? ? ? ? Scanner input=new Scanner(System.in);
? ? ? ? int a;
? ? ? ? try{
? ? ? ? ? ? a=input.nextInt();
? ? ? ? ? ? xunhuan1:
? ? ? ? ? ? if(a==1){
? ? ? ? ? ? ? ? System.out.println("請輸入圖書序號:");
? ? ? ? ? ? ? ? int num=input.nextInt();
? ? ? ? ? ? ? ? System.out.println("book:"+bookName[num-1]);
? ? ? ? ? ? }else if(a==2){
? ? ? ? ? ? ? ? System.out.println("請輸入書名:");
? ? ? ? ? ? ? ? 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("該書不存在");
? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? System.out.println("請輸入1或2");
? ? ? ? ? ? }
? ? ? ? }catch(Exception e){
? ? ? ? ? ? System.out.println("指令類型不正確,請重新輸入");
? ? ? ? }
? ? }
? ??
}
2016-06-19
為什么要用break?????