标签:style http java color 使用 文件
public interface Season {
public static final int SEASON_SPRINT = 1;
public static final int SEASON_SUMMER = 2;
public static final int SEASON_AUTUMN = 3;
public static final int SEASON_WINTER = 4;
}
@Test
public void
test02() {
printSeason(1);
printSeason(2);
printSeason(3);
printSeason(4);
printSeason(5);
}
public void printSeason(int season) {
switch
(season) {
case Season.SEASON_SPRINT :
System.out.println("现在是春天");
break;
case Season.SEASON_SUMMER :
System.out.println("现在是夏天");
break;
case Season.SEASON_AUTUMN :
System.out.println("现在是秋天");
break;
case Season.SEASON_WINTER :
System.out.println("现在是冬天");
break;
default :
System.out.println("现在是世界末日");
}
}
public enum Season {
SPRINT,
SUMMER,
AUTUMN,
WINTER
}
@Test
public void
test03() {
printSeason(Season.SPRINT);
printSeason(Season.SUMMER);
printSeason(Season.AUTUMN);
printSeason(Season.WINTER);
}
public void printSeason(Season season) {
switch (season)
{
case SPRINT:
System.out.println("现在是春天");
break;
case SUMMER:
System.out.println("现在是夏天");
break;
case AUTUMN:
System.out.println("现在是秋天");
break;
case WINTER:
System.out.println("现在是冬天");
break;
default:
System.out.println("现在是世界末日");
}
}
public enum Season {
SPRINT,
SUMMER,
AUTUMN,
WINTER;
public String printSeason() {
switch
(this.ordinal()) {
case
0 :
return
"现在是春天";
case 1
:
return
"现在是夏天";
case 2
:
return
"现在是秋天";
case 3
:
return
"现在是冬天";
default :
return "现在是世界末日";
}
}
}
@Test
public void
test04() {
for
(Season season : Season.values()) {
System.out.println(season + " : " +
season.printSeason());
}
}
public enum Season {
SPRINT("现在是春天"),
SUMMER("现在是夏天"),
AUTUMN("现在是秋天"),
WINTER("现在是冬天");
private String
info;
private
Season(String info) {
this.info
= info;
}
public String printSeason() {
return
this.info;
}
}
@Test
public void
test05() {
for
(Season season : Season.values()) {
System.out.println(season + " : " +
season.printSeason());
}
}
public enum Season {
SPRINT {
@Override
public String printSeason() {
return "现在是春天";
}
},
SUMMER
{
@Override
public String
printSeason() {
return "现在是夏天";
}
},
AUTUMN {
@Override
public
String printSeason() {
return "现在是秋天";
}
},
WINTER {
@Override
public String printSeason() {
return "现在是冬天";
}
};
public
abstract String
printSeason();
}
@Test
public void
test06() {
for
(Season season : Season.values()) {
System.out.println(season + " : " +
season.printSeason());
}
}
标签:style http java color 使用 文件
原文地址:http://www.cnblogs.com/daojoo/p/3699675.html