Java基础-枚举enum和switch的用法
package com.hspedu.homework_; public class Course441 { public static void main(String[] args) { Color green = Color.GREEN; green.show(); Color red = Color.RED; // 枚举enum和switch的用法 switch(xxx)给定一个枚举对象 switch (red) { case RED: System.out.println("红色"); break; case BLUE: System.out.println("蓝色"); break; case BLACK: System.out.println("黑色"); break; case GREEN: System.out.println("绿色"); break; case YELLOW: System.out.println("黄色"); break; default: break; } } } interface IShow { public abstract void show(); } enum Color implements IShow { RED(255, 0, 0), BLUE(0, 0, 255), BLACK(0, 0, 0), YELLOW(255, 255, 0), GREEN(0, 255, 0); private int redValue; private int greenValue; private int blueValue; Color(int redValue, int greenValue, int blueValue) { this.redValue = redValue; this.greenValue = greenValue; this.blueValue = blueValue; } @Override public void show() { System.out.print("red = " + redValue); System.out.print("\tgreen = " + greenValue); System.out.println("\tblue = " + blueValue); System.out.println("=========================="); } }