输出日期的下一天

深渊向深渊呼唤

输出日期的下一天:

package Test;
import java.util.Scanner;
public class test3 {
	public static void NextDate()
	{
	int year,mouth,day;
	int year1,mouth1,day1;
	int run=0;
	@SuppressWarnings("resource")
	Scanner input = new Scanner(System.in);
	while(true) {
	while(true)
	{
	System.out.println("请输入年份");
	year=input.nextInt();
	if(year<1000||year>9999)
	{
	System.out.println("输入数据非法");
	continue;
	}
	if((year%4==0&&year%400!=0)||year%400==0)
	run=1;
	else
	run=0;
	break;
	}
	while(true)
	{ 
		System.out.println("请输入月份");
	mouth=input.nextInt();
	if(mouth>12||mouth<1)
	{
	System.out.println("输入数据非法");
	continue;
	}
	break;
	}
	while(true)
	{
	System.out.println("请输入日期");
	day=input.nextInt();
	if(day>31||day<1)

	{
		System.out.println("输入数据非法");
	continue ;
	}
	if(day==31&&(mouth==2||mouth==4||mouth==6||mouth==9||mouth==11))
	{
	System.out.println("输入日期不存在");
	continue ;
	}

	if(day==30&&mouth==2)
	{
	System.out.println("输入日期不存在");
	continue;
	}
	if(day==29&&run==0&&mouth==2)
	{
	System.out.println("输入日期不存在");
	continue ;
	}
	break;
	}
	
	if (day==31||(day==30&&(mouth==4||mouth==6||mouth==9||mouth==11)))
	{
	if(mouth==12)
	{
	mouth1=1;
	year1=year+1;
	day1=1;

	}
	else
	{
	mouth1=mouth+1;
	year1=year;
	day1=1;
	}
	}
	else if((day==29&&mouth==2)||(day==28&&mouth==2&&run==0))
	{
	mouth1=3;
	year1=year;
	day1=1;
	}
	else
	{
	mouth1=mouth;
	day1=day+1;
	year1=year;
	}
	System.out.println("您输入的是"+year+"年"+mouth+"月"+day+"日");
	System.out.println("它的下一天是"+year1+"年"+mouth1+"月"+day1+"日\n");
	}
	}
	public static void main(String[] args) {
		NextDate();
	}

}

输出结果:
输出日期的下一天可以试试看。

栏目