蓝桥杯日期问题

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
		System.out.println((int)Math.pow(20, 22)%7+6);
        scan.close();
    }
}

import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main {
   public static void main(String[] args) {
        int countyeah=0,yeah=1777,day=0,month=4;
        String lingy="",lingr="";
        for (int i = 0; i < 8113/366; i++) {
            if (Run(++yeah)) {
                countyeah++;
            }
        }
        day =8113- (countyeah*366+(8113/365-countyeah)*365);
        while (day>=30) {
            if (month>=13) {
                month=month-12;
            }
            switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                month++;
                day-=31;
            case 4:
            case 6:
            case 9:
            case 11:
                month++;
                day-=30;
                break;
            case 2:
                if (Run(yeah)) {
                    month++;
                    day-=29;
                }
                else {
                    month++;
                    day-=28;
                }
            }
        }
        if (day>0) {
            month++;
        }
        else {
            day=29+day;
        }
        if (month<10) {
            lingy="0"+month;
        }
        else {
            lingy=month+"";
        }
        if (day<10) {
            lingr="0"+day;
        }
        else {
            lingr=day+"";
        }
        System.out.println(yeah+"-"+lingy+"-"+lingr);
    }
    
    public static boolean Run(int yeah) {
        return ((yeah%4==0&&yeah%100!=0)||yeah%400==0)?true:false;
    }
}

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        String date1 = scan.nextLine();
        String date2 = scan.nextLine();
        DateFormat format = new SimpleDateFormat("yyMMdd");
        Date enDate = format.parse(date2);
        Date start = format.parse(date1);
        long e = enDate.getTime();
        long s = start.getTime();
        System.out.println((e-s)/(60*60*24*1000)+1);
    }
}

java计算多少天后的日期

    /**
     *  计算多少天后的日期
     * @param date   手动输入日期
     * @param days   多少天后
     * @return
     * @throws ParseException
     */
    public static String addDate(String date,int days) throws ParseException {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = format.parse(date);
        calendar.setTime(parse);
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        // days  多少天后的日期
        int newDay = day+days;
        calendar.set(Calendar.YEAR,year);
        calendar.set(Calendar.MONTH,month);
        calendar.set(Calendar.DAY_OF_MONTH,newDay);
        return format.format(calendar.getTime());
    }

import java.util.Arrays;
import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main {
	static int cnt = 0;
	static int[]month = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        for (int i = 19000101; i <= 99991231; i++) {
			if (check(i)&&calc(i)&&Check(i)) {
				cnt++;
			}
		}
        System.out.println(cnt);
        scan.close();
    }
    private static boolean Check(int n) {
    	String s = n+"";
    	n = n/10000;
    	int m = Integer.parseInt(s.substring(4, 6));
    	if (!(n%4==0&&n%100!=0||n%400==0)) {//如果不是闰年 2月没有29天
    		if (Integer.parseInt(s.substring(6, 8))==29&&m==2) {
				return false;
			}
		}
    	return true;
	}
    private static boolean check(int n) {
    	String s = n+"";
    	int day =Integer.parseInt(s.substring(6, 8));
    	int m = Integer.parseInt(s.substring(4, 6));
    	if (Integer.parseInt(s.substring(4, 6))>12||Integer.parseInt(s.substring(4, 6))==0) {
    			return false;
		}
    	if (month[m]<day||day==0) {
    		return false;
    	}
    	return true;
	}
    private static boolean calc(int n) {
    	String s = n+"";
    	int a = sum(Integer.parseInt(s.substring(0, 4)));
    	int b = sum(Integer.parseInt(s.substring(4, 6)));
    	int c = sum(Integer.parseInt(s.substring(6, 8)));
    	if (a==b+c) {
			return true;
		}
    	return false;
	}
    private static int sum(int n) {
    	int Sum = 0;
		while (n>0) {
			Sum+=n%10;
			n/=10;
		}
		return Sum;
	}
}

  • 12
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值