使用enum定义枚举类

enum Week {
    MON, TUE, WED, THU, FRI, SAT, SUN
}

测试

public class WeekTest {

    public static void main(String[] args) {
        printWeek();
    }

    static void printWeek() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个数字(1-7):");
        int w = sc.nextInt();
        if (w < 1 || w > 7) {
            System.out.println("非法输入");
        } else {
            Week[] arr = Week.values();
            Week we = arr[w - 1];
            switch (we) {
                case MON:
                    System.out.println("星期一");
                    break;
                case TUE:
                    System.out.println("星期二");
                    break;
                case WED:
                    System.out.println("星期三");
                    break;
                case THU:
                    System.out.println("星期四");
                    break;
                case FRI:
                    System.out.println("星期五");
                    break;
                case SAT:
                    System.out.println("星期六");
                    break;
                case SUN:
                    System.out.println("星期日");
                    break;
            }
        }
    }
}

测试结果