枚举类简单用例

定义一个Enum.class :

package com.dvision;

public enum SeasonEnum {
 Spring,summer,fall,winter
}

 

测试枚举类:

package com.dvision;

import java.util.Scanner;

public class EnumImpl {
 public void judge(SeasonEnum s){
  switch (s) {
  case Spring:
   System.out.println("hello Spring");
   break;
  case summer:
   System.out.println("hello Summer");
   break;
  case fall:
   System.out.println("hello Fall");
   break;
  case winter:
   System.out.println("hello Winter");
   break;
  default:
   break;
  }
 }
 
 public static String readConsole(String p){
  Scanner scanner = new Scanner(System.in);
  System.out.println(p);
  return scanner.nextLine();
 }
 
 public static void main(String[] args) {
  for (SeasonEnum s : SeasonEnum.values()) {
   System.out.println(s);
  }
  System.out.println(SeasonEnum.Spring);
  EnumImpl e = new EnumImpl();
  String str = readConsole("要输入的字符串:");
  System.out.println(str);
 }
}

 

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭