文章

27

粉丝

492

获赞

10

访问

257.1k

头像
仅供参考
P1290 上海交通大学/西北工业大学2019机试
发布于2020年4月1日 00:43
阅读数 8.8k

大题思路就是对两个输入的日期进行如下判断   

1.同年        1.1 同月 

                 1.2 不同月

2.不同年

 

import java.util.Scanner;

/**
 * @author 回到原点 1.定义月份数组 2.判断闰年(写成方法) 3.对2月和年的天数进行赋值 4.计算相差天数
 */

public class Main {

	public static boolean isRunYear(int y) {
		if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)) {
			return true;
		} else
			return false;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int month[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
		Scanner sc = new Scanner(System.in);
		String str1=sc.next();
		String str2=sc.next();
		int y1 =Integer.parseInt(str1.substring(0,4));//2016
		int m1 = Integer.parseInt(str1.substring(4,6));//4
		int d1 = Integer.parseInt(str1.substring(6,8));//12
		int y2 = Integer.parseInt(str2.substring(0,4));//2019
		int m2 = Integer.parseInt(str2.substring(4,6));//4
		int ...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发