定义一个日期类,包括年,月,日三个属性和一个方法,用于判断是不是闰年,然后实例化两个对象:今天和明天,并分别给他们赋值。
package test22;
class YYY {
int year,month,day;
boolean isLeapYear() {
if((year%4==0&&year%40!=0)||year%400==0)
return true;
else
return false;
}
}
public class DateType {
public static void main(String arg[]) {
YYY thisyear,nextyear;
thisyear=new YYY();
thisyear.year=2005;
thisyear.month=6;
thisyear.day=20;
nextyear=new YYY();
nextyear.year=2018;
nextyear.month=12;
nextyear.day=10;
System.out.println("今年是否是闰年:"+thisyear.isLeapYear());
System.out.println("今年是否是闰年:"+nextyear.isLeapYear());
}
}