某个日期的下一天

/**
* 功能:输入1990至2020年间的某个日期
* 输出该日期的下一天
* @author hey_boom;
*/
import java.util.Scanner;

public class dataTest {

int year;
int month;
int day;
public dataTest(){
System.out.println("\n请输入年份(1990至2020年间):");
Scanner scanyear = new Scanner(System.in);
year = scanyear.nextInt();
System.out.println("\n请输入月份:");
Scanner scanmonth = new Scanner(System.in);
month = scanmonth.nextInt();
System.out.println("\n请输入日号:");
Scanner scanday = new Scanner(System.in);
day = scanday.nextInt();
System.out.println("你输入的日期"+year+"年"+month+"月"+day+"日\n");
if(year<1990||year>2020){
System.out.println("\n输入非法:输入数据不在判断范围内!!\n");
}
else if(!isRun(year)&&month==2&&day==29){
System.out.println("\n输入非法:该年份是平年,2月月末是28号!!\n");
}
else{
/*闰年2月*/
if(isRun(year)&&month==2&&day==28){
month=3;
day=29;
}
else if(isRun(year)&&month==2&&day==29){
month++;
day=1;
}
else if(!isRun(year)&&month==2&&day==28){
month++;
day=1;
}
/*年末*/
else if(month==12&&day==31){
year++;
month=1;
day=1;
}
/*月末*/
else if((month==1||month==3||month==5||month==7||month==8||month==10)&&day==31){
month++;
day=1;
}
else if((month==4||month==6||month==11)&&(day==30)){
month++;
day=1;
}
/*其他*/
else{
day++;
}
System.out.println("\n该日期的下一天:"+year+"年"+month+"月"+day+"日");
}

}

/*判断闰年*/
public boolean isRun(int year){
if((year%4==0&&year%100!=0)||(year%400==0))
return true;
else
return false;
}

public static void main(String[] args){
while(true){
System.out.println("\n*************************************");
new dataTest();
}
}
}

posted @ 2017-11-13 17:42  嘿boom  阅读(280)  评论(0编辑  收藏  举报