package v1ch05.EnumTest;
import java.util.*;
/**
* This program demonstrates enumerated types.
* @version 1.0 2004-05-24
* @author Cay Horstmann
*/
public class EnumTest
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter a size: (SMALL, MEDIUM, LARGE, EXTRA_LARGE) ");
String input = in.next().toUpperCase();
Size size = Enum.valueOf(Size.class, input);
System.out.println("size=" + size);
System.out.println("abbreviation=" + size.getAbbreviation());
if (size == Size.EXTRA_LARGE)
System.out.println("Good job--you paid attention to the _.");
}
}
enum Size
{
SMALL("S"), MEDIUM("M"), LARGE("L"), EXTRA_LARGE("XL");
private Size(String abbreviation)
{
this.abbreviation = abbreviation;
}
public String getAbbreviation()
{
return abbreviation;
}
private String abbreviation;
}
java枚舉類
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
二維碼生成
StringLong
2019-02-23 00:41:58
【重拾】MapReducer[第一篇]
碧玥丶Super
2019-02-23 14:06:40
openFileOutput
shyscool
2019-02-23 12:57:20
Hellow Scala
yekang12
2019-02-23 00:39:41
10個經典的 Java main 方法面試題
bigbang1991
2019-02-23 00:34:23
10個經典的 Java main 方法面試題
bigbang1991
2019-02-23 00:34:23
10個經典的 Java main 方法面試題
bigbang1991
2019-02-23 00:34:22
JS module的導出和導入
KevinYan
2019-02-24 21:34:55
Java-第六章-用for和if-elseif 完整了用戶登錄信息驗證
瘋子偉偉
2019-02-23 00:42:42
android 控件跟隨手指移動
huangwenwenlili
2019-02-23 00:41:23
centos ***
samplelife
2019-02-23 13:57:36
交換機的基本配置實驗報告
乘風來
2019-02-23 13:00:59
交換機的基本配置實驗報告
1406404037
2019-02-23 12:50:57