1 Package Penalty for com.project; 2 Import java.util.InputMismatchException; 3 / ** 4 * Number Course Name output according to 5 * according to the keyboard input to determine 6 * Whether or not entered correctly, outputs "open to suggestions!" 7 * @ author L . 8 * / . 9 Import java.util.Scanner; 10 . 11 public class the Project { 12 is static Scanner SC = new new Scanner (the System.in); 13 is public static void main (String [] args) { 14 of System.out.print ( "Please enter the course code (a number between 1 to 3):"); 15 try { 16 int num=sc.nextInt(); 17 if(num>=1&&num<=3) { 18 //判断数字 19 switch(num) { 20 case 1: 21 System.out.println("Java课程"); 22 break; 23 case 2: 24 System.out.println("C#课程"); 25 break; 26 case 3: 27 System.out.println("C++课程"); 28 break; 29 } 30 }else { 31 System.out.println("输入有误,没有对应课程!"); 32 } 33 }catch(InputMismatchException e){ 34 System.err.println("输入类型有误"); 35 e.printStackTrace(); 36 }catch(Exception e) { 37 System.out.println("输入有误"); 38 }finally { 39 System.out.println("欢迎提出建议!"); 40 } 41 } 42 }