异常练习
package cn.yichang; import java.util.InputMismatchException; import java.util.Scanner; public class Class { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { String[] kgc = {"C#编程","JAVA编程","汇编编程"}; try { System.out.println("请输入课程代号(1~3之间的数字):"); int num = sc.nextInt(); System.out.println(kgc[num-1]); }catch(InputMismatchException e) { System.out.println("你输入的不是数字"); }catch(ArrayIndexOutOfBoundsException e) { System.out.println("你输入的数字不在范围之内"); }finally { System.out.println("欢迎提出建议"); } } }