定义一个Date类,成员变量year,month和day,成员方法包括input_Date()和out_putDate(),分别用于实现日期的

2024-12-19 17:41:44
推荐回答(2个)
回答1:

public class Date{
private int year,month,day;
public Date(){
}
public void input_Date(int year,int month,int day){
this.year = year;
this.month = month;
this.day = day;
}
public void output_Date(){
System.out.println("日期是:"+year+"年"+month+"月"+day+"日");
}
}
//测试类
public class Test{
public static void main(String args[]){
Date date = new Date();
Scanner input = new Scanner(System.in);
System.out.println("请输入年月日:");
int year = input.nextInt();
int month = input.nextInt();
int day = input.nextInt();
date.input_Date(year,month,day);
date.output_Date();
}
}

回答2:

分别实现日期的什么?