Java

java的enum用法示例

小樊
84
2024-08-18 18:02:35
栏目: 编程语言

enum Season { SPRING, SUMMER, AUTUMN, WINTER }

public class EnumExample { public static void main(String[] args) { Season currentSeason = Season.SUMMER;

    switch(currentSeason) {
        case SPRING:
            System.out.println("It is spring season.");
            break;
        case SUMMER:
            System.out.println("It is summer season.");
            break;
        case AUTUMN:
            System.out.println("It is autumn season.");
            break;
        case WINTER:
            System.out.println("It is winter season.");
            break;
    }
}

}

0
看了该问题的人还看了