⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chap7-3.txt

📁 清华大学出版社经典教材系列
💻 TXT
字号:
// 程序7-3
public class testFinally{
    public static void main(String args[ ]) {
        int a,b=0;
        
        for(int i=0;i<3;i++){
            System.out.println("Test No: "+(i+1));
            try{
                switch(i){
                    case 0:  a=3/b;			// 0作除数
                            break;
                    case 1:  int  c[ ]=new int[10];
                            c[10]=0;			// 数组下标越界
                            break;
                    case 2:  char ch="ABC".charAt(99);	//字符串的下标越界
                            break;
                    case 3:  return;			// 通过return语句结束程序
                }
            }catch(ArithmeticException  e) {
                System.out.println("零作除数!");
            }catch(ArrayIndexOutOfBoundsException  e) {
                System.out.println("数组下标越界!");
            }catch(IndexOutOfBoundsException  e) {
                System.out.println("下标越界!");
            }finally{
                System.out.println("在finally块中!");
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -