解题思路:
闰年的问题,闰年二月有29天,平年二月有28天

普通闰年:公历年份是4的倍数的,且不是100的倍数。世纪闰年:公历年份是整百数的,必须是400的倍数才是世纪闰年。

注意事项:
  当为一二月的时候 闰年是不用加一的(因为没过完2月)
参考代码:

import java.util.Scanner;
public class Main {
	static  class date{
        int year;
        int month;
        int day;
    }
	public static void main(String[] args) {
		date t= new date();
        Scanner scanner=new Scanner(System.in);
        t.year = scanner.nextInt();
        t.month =scanner.nextInt();
        t.day =scanner.nextInt();
        int[] m= {31,28,31,30,31,30,31,31,30,31,30,31};
        int n=0;
        for (int i = 0; i < t.month-1; i++) 
			n+=m[i];	
        n+=t.day;
        if (t.month>2) 
        if (t.year%4==0&&t.year%100!=0||t.year%400==0)
        	n++;
        System.out.println(n);
}
}


 

0.0分

2 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区