import java.util.*;
class Main{
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int val=sc.nextInt();
Lights light=Lights.valueOf(val);
//How to take the value of variable "val" so that if we print '0' Red is displayed.
int set=light.setVal(val);
System.out.println(light.getVal());
}}
enum Lights {
Red(0), Yellow(1), Green(2);
int i;
Lights(int i) { this.i=i; }
int getVal() { return i; }
void setVal(int m) { i=m;}
}
枚举定义时如何使用“val”的值..?
例如,在命令行参数的情况下,我们编写 valueOf(args[0]) 但在这种情况下,当我们想使用“val”时应该做什么..?