-
题目描述:
-
有两个日期,求两个日期之间的天数,如果两个日期是连续的我们规定他们之间的天数为两天
-
输入:
-
有多组数据,每组数据有两行,分别表示两个日期,形式为YYYYMMDD
-
输出:
-
每组数据输出一行,即日期差值
-
样例输入:
-
20110412 20110422
-
样例输出:
-
11
Java AC 代码:
import java.util.Scanner;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int date1, date2;
Scanner inScanner = new Scanner(System.in);
while (inScanner.hasNext()) {
date1 = inScanner.nextInt();
date2 = inScanner.nextInt();
int temp;
if (date1 > date2) {
temp = date1;
date1 = date2;
date2 = temp;
}
int year1, month1, day1, year2, month2, day2;
year1 = date1 / 10000;
month1 = (date1 / 100) % 100;
day1 = date1 % 100;
year2 = date2 / 10000;
month2 = (date2 / 100) % 100;
day2 = date2 % 100;
System.out.println(diff(year1, month1, day1, year2, month2, day2));
}
}
public static boolean isLeap(int year) {