Lev1

导航

异常练习

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("欢迎提出建议");
            }
        }
}

 

posted on 2019-07-23 18:03  Lev1  阅读(117)  评论(0编辑  收藏  举报