Enum 枚举

    xiaoxiao2022-07-06  201

    // 程序中的问题能在编译阶段解决的绝对不在运行阶段解决 ,所以引入枚举类型 public static void main(String[] args) { int a = 10; int b = 2; result d = divide(a, b); if (d == result.SUCCESS) { System.out.println("cheng"); } else if (d == result.FALL) { System.out.println("shibai"); } } public static result divide(int a, int b) { try { int c = a / b; return result.SUCCESS; } catch (Exception e) { return result.FALL; } } } //定义一个枚举类型 enum result{ //规范大写 SUCCESS,FALL } enum SEAON{ SPRING,SUMMER,AUTUOM,WINTER } enum color{ BLUE,SEW,s; }

     

    最新回复(0)