為什么這樣設置序號的時候,數組下標越界異常 不會報出“圖書不存在”
private static String getBookByNumber(String[] books)throws Exception{
System.out.println();
System.out.println("輸入書的序號:");
?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
肯定不會顯示啊,你這段代碼完全有問題的,加上try-catch