一个java程序的异常处理
package com.cn.homework;import java.util.InputMismatchException;
import java.util.Scanner;
public class Menu {
private static Scanner sc;
private static Scanner reader;
//private static String j;
public static void main(String atgs []){
String[] str = {"显示帮助","设置班级","设置兼职老师","设置全职老师","设置学员",
"设置课程","设置教师","自我设置","显示信息","退出系统"};
StringBuilder sb = new StringBuilder();
sb.append("*****显示帮助*******");
sb.append("\n");
for(int i=0;i<10;i++){
sb.append(i+"--------"+str[i]+"\n");
}
sb.append("请从0~9中选择数字输入:");
System.out.println(sb);
while(true){
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
String s = sc.next();
if(i==0){
try{
while(reader.hasNextInt()){
System.out.println("显示帮助:");
}
}catch(NullPointerException e){
e.printStackTrace();
}
}
else if(i==1){
try{
while(reader.hasNextInt()){
}
}catch(NullPointerException e){
System.out.println("设置班级:");
}
}
else if(i == 2){
try{
while(reader.hasNextInt()){
}
}catch(NullPointerException e){
System.out.println("设置兼职老师:");
}
}
else if(i==3){
try{
while(reader.hasNextInt()){
}
}catch(NullPointerException e){
System.out.println("设置全职老师:");
}
}
}
}
try{
//i = sc.nextInt();
s = sc.next();
}catch(InputMismatchException e){
System.out.println("输入错误,请输入0~9的数字!程序运行结束!");
}
}
}
}
请问如何处理用户输入的非数字和非指定范围内的数字呢,麻烦帮帮忙,谢谢了