為什么這樣設(shè)置序號(hào)的時(shí)候,數(shù)組下標(biāo)越界異常 不會(huì)報(bào)出“圖書不存在”
private static String getBookByNumber(String[] books)throws Exception{
System.out.println();
System.out.println("輸入書的序號(hào):");
?int num =input.nextInt();
?
? ? ?for(int i = 0; i < books.length; i++) {
? ? if (books[num-1].equals(books[i])){
? ? return books[i];
? ? }
? ? }throw new Exception("圖書不存在!");
? ? ?}
?
2017-02-26
肯定不會(huì)顯示啊,你這段代碼完全有問題的,加上try-catch