public static void main(String args[]) {
int i = 0; String greetings[] = { " Hello world !", " Hello World !! ", " HELLO WORLD !!!" }; while (i < 4) { try { System.out.println(greetings[i++]); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("數(shù)組下標越界異常"); } finally { System.out.println(i); } } }
輸出結(jié)果為:
Hello world !1 Hello World !! 2 HELLO WORLD !!!3數(shù)組下標越界異常4