62,614
社区成员
发帖
与我相关
我的任务
分享
public enum Day{
MONDAY,TUESDAY, WENDSDAY, THURSDAY,
FRIDAY, SATURDAY, SUNDAY
}
public class theDay {
public static final int mon = 1;
public static final int tue = 2;
public static final int wen = 3;
public static final int thr = 4;
public static final int fri = 5;
public static final int sat = 6;
public static final int sun = 7;
}
enum day {
mon(1),tue(2),wen(3),thu(4),fri(5),sat(6),sun(0);//自动调用构造方法创建静态实例
private int value;//属性
private day(int value) {this.value=value;}
public String toString() {
return String.format("%d", value);
}
public day plus(day d) { //加个方法
for (day dd : day.values()) {
if ((this.value+d.value)%7 == dd.value) {
return dd;
}
}
return null;
}
}
public class Sample {
public static void main(String[] args) {
System.out.println(day.mon);
System.out.println(day.mon.plus(day.mon));
}
}
enum day {
mon(1),tue(2),wen(3),thu(4),fri(5),sat(6),sun(0);//自动调用构造方法创建静态实例
private int value;//属性
private day(int value) {this.value=value;}
public String toString() {
return String.format("%d", value);
}
}
public class Sample {
public static void main(String[] args) {
System.out.println(day.mon);
}
}
[/quote]
谢谢。好了。
但是如果我要System.out.println(day.mon + day.mon) 返回2,如何写?day.mon返回1,但不能参与各种运算也没什么意义。enum day {
mon(1),tue(2),wen(3),thu(4),fri(5),sat(6),sun(0);//自动调用构造方法创建静态实例
private int value;//属性
private day(int value) {this.value=value;}
public String toString() {
return String.format("%d", value);
}
}
public class Sample {
public static void main(String[] args) {
System.out.println(day.mon);
}
}