输出日期的下一天

输出日期的下一天:

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();
	}

}

输出结果:
在这里插入图片描述可以试试看。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值