枚举类
- 简介
-
- 不用枚举类的情况
package com.day0217_2;
public class MySeason {
public static final int SPRING=0;
public static final int SUMMER=1;
public static final int AUTUMN=2;
public static final int WINTER=3;
public static void main(String[] args) {
System.out.println(MySeason.AUTUMN);
}
}
package com.day0217_2;
import java.util.Random;
public class TestEnum {
public static void main(String[] args) {
System.out.println(Season.AUTUMN);
for(Week k:Week.values()){
System.out.println(k);
}
Week[] ws =Week.values();
System.out.println(ws[0]);
int a=new Random().nextInt(4);
switch (Season.values()[a]){
case SPRING:
System.out.println("春天");
break;
case SUMMER:
System.out.println("夏天");
break;
case AUTUMN:
System.out.println("秋天");
break;
case WINTER:
System.out.println("冬天");
break;
}
}
}
enum Season{
SPRING,SUMMER,AUTUMN,WINTER
}
enum Week{
星期一,星期二,星期三,星期四,星期五,星期六,星期日
}
版权声明:本文内容来自第三方投稿或授权转载,原文地址:https://jsss-1.blog.csdn.net/article/details/113850141,作者:日星月云,版权归原作者所有。本网站转在其作品的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如因作品内容、版权等问题需要同本网站联系,请发邮件至ctyunbbs@chinatelecom.cn沟通。