文章
27
粉丝
492
获赞
10
访问
268.9k
import java.util.Scanner;
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
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
for(int i=0;imonth[m]) {
if(m==12) { //m为12时,且上面已经判断sumDay超过12月的天数,当然年份要+1啦
y++;
if(isRunYear(y)) { //对新的年份要对二月赋值,首先对闰年判断
month[2]=29;
}else {
month[2]=28;
}
}
sumDay-=month[m];
m=(m+1)%12; //不取模的话,m++数组会越界,m++到12取模后变为0,要还原m的值
if(m==0) {
m=12;
}
}
System.out.printf("%d-%02d-%02d\n",y,m,sumDay);
}
}
}
登录后发布评论
暂无评论,来抢沙发