运行过了: import java.util.Scanner; public class Test { public void print(int date) { switch(date) { case 1: System.out.println("星期一"); break; case 2: System.out.println("星期二"); break; case 3: System.out.println("星期三"); break; case 4: System.out.println("星期四"); break; case 5: System.out.println("星期五"); break; case 6: System.out.println("星期六"); break; default: System.out.println("星期日"); } } public static void main(String[] args) { Scanner ss = new Scanner(System.in); try { int dd = Integer.parseInt(ss.next()); if(dd>7||dd<1) { System.out.println("您输入的数字有错误,请输入1到7的数字"); } else { new Test().print(dd); } } catch(Exception e) { System.out.println("您的输入有误,请输入1到7的数字"); } } }