您的位置:首页 > 其它

这是判断日期是否合法的程序。相信有助于你。

2009-02-23 16:58 183 查看
public class Mydate {
int year;
int month;
int day;

public Mydate(int year,int month,int day){
this.year = year;
this.month = month;
this.day = day;
}
public void newdate(){
System.out.println(this.year+"年"+this.month+"月"+this.day+"日");
if(year<0||month<=0||day<=0||month>12||day>31)
System.out.println("输入的是非法日期");
if(month==4||month==6||month==9||month==11&&day>30)
System.out.println("输入的是非法日期");
if(month==2 && ((year%4 == 0 && year%100 != 0) || (year%400 == 0))){
if(day>29)
System.out.println("输入的是非法日期");
}
}
public static void main (String[] args) {
Mydate date1 = new Mydate(2008,2,29);
date1.newdate();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: