学习java的第30天
//枚举类型enum Mm{
a,b,c,d;
}
enum Season{
SPRING,SUMMER,FALL,WINTER
}
public class mj {
public static void main(String[] args) {
Mm m1=Mm.a;
Mm m2=Mm.b;
Mm m3=Mm.c;
Mm m4=Mm.d;
System.out.println("a:"+m1.ordinal());
System.out.println("b:"+m2.ordinal());
System.out.println("c:"+m3.ordinal());
System.out.println("d:"+m4.ordinal());
//遍历枚举类型
for(Season se:Season.values()) {
System.out.println(se+":"+se.ordinal());
}
}
}[
//结果:
a:0
b:1
c:2
d:3
SPRING:0
SUMMER:1
FALL:2
WINTER:3
//枚举类型让使用数字代表一个类型更加直观 {:9_239:}
页:
[1]