?? date.java
字號(hào):
//Date.java
public class Date {
private int month;
private int day;
private int year;
public Date( int theMonth, int theDay, int theYear ){
month = checkMonth( theMonth );
year = theYear;
day = checkDay( theDay );
System.out.println( "Date object constructor for date " +
toDateString() );
}
private int checkMonth( int testMonth ){ //檢測(cè)月份的合法性
if ( testMonth > 0 && testMonth <= 12 )
return testMonth;
else {
System.out.println( "Invalid month (" + testMonth +
") set to 1." );
return 1;
}
}
private int checkDay( int testDay ){ //檢測(cè)日期的合法性
int daysPerMonth[] =
{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if ( testDay > 0 && testDay <= daysPerMonth[ month ] )
return testDay;
if ( month == 2 && testDay == 29 && ( year % 400 == 0 ||
( year % 4 == 0 && year % 100 != 0 ) ) )
return testDay;
System.out.println( "Invalid day (" + testDay + ") set to 1." );
return 1;
}
public String toDateString(){
return month + "/" + day + "/" + year;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -