package com;
public enum Color {
RED, GREEN, BLANK, YELLOW
}
package com;
public class B {
public static void main(String[] args) {
System.out.println( isRed( Color.BLANK ) ) ; //结果: false
System.out.println( isRed( Color.RED ) ) ; //结果: true
}
static boolean isRed( Color color ){
if ( Color.RED.equals( color )) {
return true ;
}
return false ;
}
}
package com;
public class B {
public static void main(String[] args) {
showColor( Color.RED );
}
static void showColor(Color color){
switch ( color ) {
case BLANK:
System.out.println( color );
break;
case RED :
System.out.println( color );
break;
default:
System.out.println( color );
break;
}
}
}
package com;
public enum Color {
RED("红色", 1), GREEN("绿色", 2), BLANK("白色", 3), YELLO("黄色", 4);
private String name ;
private int index ;
private Color( String name , int index ){
this.name = name ;
this.index = index ;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
}
package com;
public class B {
public static void main(String[] args) {
//输出某一枚举的值
System.out.println( Color.RED.getName() );
System.out.println( Color.RED.getIndex() );
//遍历所有的枚举
for( Color color : Color.values()){
System.out.println( color + " name: " + color.getName() + " index: " + color.getIndex() );
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有