Mom,Tue,Wed,Thu,Fri,Sat,Sun判断周几

  //根据单词判断今天是星期几
public class dome {
public static void main(String[] args) {
day day1 =  day.Mom;
day1.show();

day day2 = day.Fri;
day2.show();
}
 


}


//   方法二
    enum day2{
    Mom {
@Override
public void show() {
// TODO Auto-generated method stub
System.out.println("周一");
}
},Tue {
@Override
public void show() {
// TODO Auto-generated method stub
System.out.println("周二");
}
},Wed {
@Override
public void show() {
// TODO Auto-generated method stub
System.out.println("周三");
}
},Thu {
@Override
public void show() {
// TODO Auto-generated method stub
System.out.println("周四");
}
},Fri {
@Override
public void show() {
// TODO Auto-generated method stub
System.out.println("周五");
}
},Sat {
@Override
public void show() {
// TODO Auto-generated method stub
System.out.println("周六");
}
},Sun {
@Override
public void show() {
// TODO Auto-generated method stub
System.out.println("周日");
}
};
   
    public abstract void show();
    }


// 方法一
enum day{
   Mom,Tue,Wed,Thu,Fri,Sat,Sun;
   public void show(){
  if (this.name().equals("Mom")) {
System.out.println("周一");
}
  else if (this.name().equals("Tue")) {
System.out.println("周二");
}
  else if (this.name().equals("Wed")) {
System.out.println("周三");
}
  else if (this.name().equals("Thu")) {
System.out.println("周四");
}
  else if (this.name().equals("Fri")) {
System.out.println("周五");
}
  else if (this.name().equals("Sat")) {
System.out.println("周六");
}
 
  else if (this.name().equals("Sun")) {
System.out.println("周日");
}
 
   }
}

你可能感兴趣的:(枚举的使用,枚举,java加强,枚举,Javaee)