public enum Friend
{
FQ1("花花", "籃 球", "中興高中", "真理大學"),
FQ2("凱子", "籃 球", "大安高工", "百齡高中"),
FQ3("小鄭", "兜 風", "大安高工", "沒有在學"),
FQ4("顏乃", "抬拳道", "南港高工", "華夏技院"),
FQ5("小光", "音 樂", "方濟中學", "東南大學");
private final String n;
private final String h;
private final String b;
private final String w;
Friend ( String Name, String Hobby, String Before, String Now )
{
n = Name;
h = Hobby;
b = Before;
w = Now;
}
public String getName()
{
return n;
}
public String getHobby()
{
return h;
}
public String getBefore()
{
return b;
}
public String getNow()
{
return w;
}
}
import java.util.EnumSet;
public class EnumTest
{
public static void main ( String args [] )
{
System.out.println("好友們:\n");
for ( Friend friend : Friend.values() )
System.out.printf("%-6s %-8s %-8s %-10s %-10s\n",
friend, friend.getName(), friend.getHobby(),
friend.getBefore(), friend.getNow() ) ;
System.out.println("\n有機車的好友:\n");
for ( Friend friend : EnumSet.range(Friend.FQ2, Friend.FQ4) )
System.out.printf("%-6s %-8s %-8s %-10s %-10s\n",
friend, friend.getName(), friend.getHobby(),
friend.getBefore(), friend.getNow() ) ;
}
}
java EnumTest
java EnumTest
留言列表