try_catch_finally.java
来自「主要介绍了JAVA的基本知识和异常处理的知识」· Java 代码 · 共 33 行
JAVA
33 行
public class try_catch_finally{
public static void main (String args[]) {
int i = 0;
String greetings [] = {
"1 Hello world!",
"2 No, I mean it!",
"3 HELLO WORLD!!"
};
while (i < 4) {
try {
System.out.println (greetings[i]);
} catch (ArrayIndexOutOfBoundsException e){
System.out.println( "数组下标越界");
} finally {
System.out.println("This is always printed");
}
i++;
} // end while()
} // end main()
}
/* 当循环被执行时,下述在屏幕上出现的信息将改变。
1 Hello world!
This is always printed
2 No, I mean it!
This is always printed
3 HELLO WORLD!!
This is always printed
数组下标越界
This is always printed */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?