本人刚刚开始学,只是记录一下自己的学习过程
package FirstWeekTest; import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner scan=new Scanner(System.in); int year1,year2; int day=0; year1= scan.nextInt(); year2=scan.nextInt(); if(year1<=0||year2<=0){ System.out.println("不合法);//输入年份不得小于或等于0 }else{ if(year1<year2) {//对比输入的年份大小 for (year1 = year1; year1 <= year2; year1++) { if (year1 % 4 == 0 && year1 % 100 != 0 || year1 % 400 == 0) { day += 366;//闰年的天数是366 year1++;//年份小的年份自增一年 } else { day += 365;//非闰年增365天 year1++; } } System.out.println("相差"+day); }else { for (year1 = year1; year1 >= year2; year1++) { if (year1 % 4 == 0 && year1 % 100 != 0 || year1 % 400 == 0) { day += 366; year2++; } else { day += 365; year2++; } } System.out.println("相差"+day); } }
}
}