public class MiDiXi {
//方法一:main方法中调用输出方法printDate()
int year;
int month;
int day;
void getYear(int y,int m,int d){
year=y;
month=m;
day=d;
System.out.println("输入日期");
}
void setYear(){
MiDiXi year=new MiDiXi();
MiDiXi month=new MiDiXi();
MiDiXi day=new MiDiXi();
}
void printDate(){
System.out.println(year+"-"+month+"-"+day);
}
public static void main(String[] args) {
MiDiXi a=new MiDiXi();
a.year=2020;
a.month=3;
a.day=17;
a.printDate();
}
//方法二:
int year;
int month;
int day;
void getYear(int y,int m,int d){
year=y;
month=m;
day=d;
}
void setYear(int y,int m,int d){
year=y;
month=m;
day=d;
System.out.println(year+"-"+month+"-"+day);
}
public static void main(String[] args) {
MiDiXi a=new MiDiXi();
a.setYear(2020,12,3);
}
Java定义一个点日期MyDate,包含三个成员变量year、month、day 表示年、月、日,每个属性对应get和set方法,最后printDate()方法,按照“yyy~mm~dd”的形式输出
最新推荐文章于 2023-08-22 10:18:47 发布