switch case异常处理机制

public class T3{
    public static void main(String[] args) {
            try{
                String kc="";
                System.out.println("请输入课程名称1,java,2,c++,3,js");
                Scanner input = new Scanner(System.in);
                int n=input.nextInt();
                switch (1){
                    case 1:
                        kc="java";
                        System.out.println("你选择的课程是"+kc);
                        break;
                    case 2:
                        kc="c++";
                        System.out.println("你选择的课程是"+kc);
                        break;
                    case 3:
                        kc="js";
                        System.out.println("你选择的课程是"+kc);
                        break;

                }
            }catch (Exception e){
                System.out.println("请输入相应的数字");
            }finally {
                System.out.println("欢迎指导");
            }
        System.out.println("退出");

    }
}

 

posted @ 2017-07-27 16:33  斯丢皮德曼  阅读(1888)  评论(0编辑  收藏  举报