作业1

 

 

package Exception;

import java.util.InputMismatchException;
import java.util.Scanner;

public class Demo03 {

    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        
        
        
        System.out.print("请输入课程代号(1~3之间的数字):");
        try {
        int num = sc.nextInt();
        if(num>=1&&num<=3) {
        switch(num) {
        
        
        case 1:
            System.out.println("Java");
            break;
        case 2:
            System.out.println("C++");
            break;
        case 3:
            System.out.println("C语言");
            break;
            
        }
        }else {
            
            System.out.println("没有该门课程");
            
        }
        
        }catch(InputMismatchException e) {
            
            System.err.println("输入的不是整数");
            
            e.printStackTrace();
        }catch(Exception e) {
            
            System.out.println("输入错误");
        }
        finally {
            
            System.out.println("欢迎提出建议!");
            
        }
        
    }
}

 

posted @ 2019-07-22 15:57  AxeBurner  阅读(103)  评论(0编辑  收藏  举报