枚举

public  enum  Season {
     SPRING,SUMMER,AUTUMN,WINTER

}

public  class  HelloWorld {
     public  static  void  main(String[] args) {
         Season season = Season.SPRING;
         switch  (season) {
         case  SPRING:
             System.out.println( "春天" );
             break ;
         case  SUMMER:
             System.out.println( "夏天" );
             break ;
         case  AUTUMN:
             System.out.println( "秋天" );
             break ;
         case  WINTER:
             System.out.println( "冬天" );
             break ;
         }
   

遍历:

public  class  HelloWorld {
     public  static  void  main(String[] args) {
         for  (Season s : Season.values()) {
             System.out.println(s);
         }
     }
}




//HeroType.java
public  enum  HeroType{
     TANK,
     WIZARD,
     ASSASSIN,
     ASSIST,
     WARRIOR,
     RANGED,
     PUSH,
     FARMING
}
 
//Hero.java
public  class  Hero{
     public  static  void  main(String[] args) {
         for (HeroType a : HeroType.values()) {
             switch  (a) {
         case  TANK:
             System.out.println( "坦克" );
             break ;
         case  WIZARD:
             System.out.println( "法师" );
             break ;
         case  ASSASSIN:
             System.out.println( "刺客" );
             break ;
         case  ASSIST:
             System.out.println( "辅助" );
             break ;
         case  WARRIOR:
             System.out.println( "近战" );
             break ;
         case  RANGED:
             System.out.println( "远程" );
             break ;
         case  PUSH:
             System.out.println( "推进" );
             break ;
         case  FARMING:
             System.out.println( "打野" );
             break ;
         }
         }      
     }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值