zoukankan      html  css  js  c++  java
  • Document

     1 package com.mon10.day22;
     2 
     3 /**
     4  * 类说明 :枚举类型,案例二
     5  * 
     6  * @author 作者 : chenyanlong
     7  * @version 创建时间:2017年10月22日
     8  */
     9 public class EnumDemoTwo {
    10 
    11     public enum ColorSelect {
    12         red, green, yellow, blue;
    13     }
    14 
    15     public static void main(String[] args) {
    16         /*
    17          * 枚举类型是一种类型,用于定义变量,用于限制变量的赋值 ,赋值时通过"枚举名.值",来取得相关枚举的值。
    18          */
    19         ColorSelect m=ColorSelect.blue;
    20         
    21         //switch方法判断
    22         switch(m){
    23             /*
    24              * 注意:枚举类型重写了ToString(),说以枚举变量的值是不带前缀的,
    25              * 所以为blue而非ColorSelect.blue
    26              */
    27             case red:
    28                 System.out.println("color is red");
    29                 break;
    30             case green:
    31                 System.out.println("color is green");
    32                 break;
    33             case yellow:
    34                 System.out.println("color is yellow");
    35                 break;
    36             case blue:
    37                 System.out.println("color is blue");
    38                 break;
    39         }
    40         
    41         //遍历方法
    42         System.out.println("---------------------------");
    43         System.out.println("遍历输入ColorSelect中的值");
    44         for(ColorSelect c:ColorSelect.values()){
    45             System.out.println(c);
    46         }
    47         
    48         System.out.println("---------------------------");
    49         System.out.println(ColorSelect.blue.ordinal());
    50         
    51 
    52     }
    53 
    54 }

    运行效果图:

  • 相关阅读:
    [Leetcode] Merge Intervals
    [Leetcode] Sort Colors
    junit
    DBUnit的使用
    xml简介---来自百度百科
    今天开始深入学习XML
    Java 用Myeclipse部署项目基础坏境搭建
    properties配置文件读取方法
    Java web做服务器之间的通信方法
    Java Socket简单的客服端及其服务器端
  • 原文地址:https://www.cnblogs.com/chenyanlong/p/7707928.html
Copyright © 2011-2022 走看看