package com.oned9z;
import java.util.InputMismatchException;
import java.util.Scanner;/**
* @program: com.oned9z * @description:输出课程名称 * @author: Mr.Lin * @create: 2019年7月22日 **/public class Course { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { System.out.println("请输入课程代号(1~3之间的数字):"); //定义课程数组 String[] courses = {"C#编程","数学","语文"}; int choose = 0; try{ choose = sc.nextInt(); System.out.println(courses[choose-1]); }catch(InputMismatchException e){ //捕捉非数字异常 System.out.println("您输入的不是数字!"); }catch(ArrayIndexOutOfBoundsException e) { System.out.println("请输入1~3之间的整数"); }finally { System.out.println("欢迎提出建议!"); } }}