📄 datetest.java
字号:
//DateTest.java
public class DateTest{
private int day, month, year;
DateTest(int i, int j, int k){//构造方法
day=i; month=j; year=k;
}
DateTest(){ //构造方法
day=1; month=7; year=2007;
}
DateTest(DateTest d){ //构造方法
day=d.day; month=d.month; year=d.year;
}
public void printDate(){
System.out.println(day + "/" + month + "/" + year);
}
public DateTest tomorrow(){
DateTest d = new DateTest(this);
d.day++;
if(d.day>d.daysInMonth()) {
d.day = 1; d.month++;
if(d.month>12){
d.month = 1; d.year++;
}
}
return d;
}
public int daysInMonth() {
switch(month){
case 1: case 3: case 5: case 7: //大月
case 8: case 10:case 12: //大月
return 31;
case 4: case 6: case 9: case 11://小月
return 30;
default:
if((year%100 !=0 && year%4==0)||(year%400==0)){//闰年
return 29; //闰年,2月
}
else return 28;//非闰年,2月
}
}
public static void main(String args[]){
DateTest d1=new DateTest();
System.out.print("The current date is(dd/mm/yy) ");
d1.printDate();
System.out.print("Its tomorrow is ");
d1.tomorrow().printDate();
DateTest d2 = new DateTest(28, 2, 2000);
System.out.print("The current date is ");
d2.printDate();
System.out.print("Its tomorrow is ");
d2.tomorrow().printDate();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -