JAVA程序设计题:定义一个表示日期的MyDate类,要求如下:

2024-11-16 04:17:58
推荐回答(2个)
回答1:

package com.model;

public class MyData {
private int year;
private int month;
private int day;
public MyData(int year,int month,int day){
this.year=year;
this.month=month;
this.day=day;
}
public int getYear() {
return year;
}

public void setYear(int year) {
this.year = year;
}

public static boolean isLeapYear(MyData data){
int year = data.getYear();
if(year%4==0&&year%100!=0){

return true;
}
if(year%400==0){
return true;
}

return false;
}
public static void main(String[] args) {
MyData data = new MyData(500, 12, 21);
System.out.println(MyData.isLeapYear(data));
}
}

回答2:

需要的Hi我或者私信我。