首页 >

判断闰年

java 有手就行
import java.util.Scanner;
import java.time.LocalDate;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner src = new Scanner(System.in);
        int a = src.nextInt();
        LocalDate ld = LocalDate.of(a,3,1);




        LocalDate ld2 = ld.minusDays(1);
        int day = ld2.getDayOfMonth();
        if(day == 29){
            System.out.print("yes");
        }
        else{
            System.out.print("no");
        }
    }

}

#include<iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;
    if (n % 400 == 0 || n % 4 == 0 && n % 100 != 0) cout << "yes" << endl;
    else cout << "no" << endl;
}

发表于 2022-02-26 14:07:32 回复(2)
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a;
    cin >>a;
    if(a%4==0 && a%100!=0){
        cout<<"yes"<<endl;
           
    }
    else if(a%400==0){
        cout<<"yes"<<endl;
    }
    else{
        cout<<"no"<<endl;
    }
    return 0;
}
发表于 2024-11-25 18:48:51 回复(0)
//能被4整除但不能被100整除的年份是闰年,能被400整除的年份也是闰年。
//2024年是闰年,因为它可以被4整除,但不能被100整除。
//1900年不是闰年,因为它可以被100整除,但不能被400整除。
//1600年是闰年,可以被4整除,也能被100整除,但它同时也能被400整除。

#include <stdio.h>

int main()
{
    int a = 0;
    scanf("%d", &a);
    
    if(a % 400 == 0)
    {
        printf("yes\n");
    }
    else
    {
        if(a % 4 == 0 && a % 100 != 0)
        {
            printf("yes\n");
        }
        else {
            printf("no\n");
        }
    }
    return 0;
}

发表于 2024-01-28 21:56:09 回复(0)
#include <stdio.h>
//闰年的判断方法可以简化为:
// 1. 能被4整除但不能被100整除的年份是闰年
// 2. 能被400整除的年份也是闰年
int main() {
    int n=0;
    scanf("%d",&n);
    if((n%4==0&&n%100!=0)||(n%400==0))
    {
        printf("yes");
    }
    else {
    {
        printf("no");
    }
    }
    return 0;
}

发表于 2024-01-13 10:15:36 回复(0)
n=int(input())
if (n%4==0 and n%100!=0)&nbs***bsp;n%400==0:
    print('yes')
else:
    print('no')    

发表于 2023-01-18 09:44:35 回复(0)
year= int(input())
if year % 400 == 0:
    print('yes')
elif (year % 4 == 0) and (year % 100 != 0):
    print('yes')
else:
    print('no')
发表于 2022-03-17 19:16:16 回复(1)
using System;
public class Program {
    public static void Main() {
        string[] input = Console.ReadLine().Split();
        int n = int.Parse(input[0]);
        if(n%400==0 || n%4==0 && n%100!=0)
        {
            Console.WriteLine("yes");
        }else
        {
            Console.WriteLine("no");
        }
    }
}
发表于 今天 00:42:18 回复(0)
#include <iostream>
using namespace std;

int main() {
    int a;
    cin >> a;
    if(a %400 == 0){
        cout << "yes";
    }else if( a%4 == 0 && a%100 !=0) {
        cout << "yes";
    } else {
        cout << "no";
    }
}

发表于 2025-07-14 11:42:31 回复(0)
jdk8以后的时间类新加了isleap方法可以直接判断是否是闰年。
发表于 2025-07-13 23:47:14 回复(0)
n = int(input())

if n % 400 == 0:
    print ("yes")
elif (n % 4 == 0) & (n % 100 !=0):
    print ("yes")
else:
    print("no")
发表于 2025-07-13 05:50:48 回复(0)
n = int(input())
print('yes' if n % 400 == 0 or (n % 4 ==0 and n %100 != 0) else 'no' )
发表于 2025-07-10 09:59:47 回复(0)
java 有手就行
import java.util.Scanner;
import java.time.LocalDate;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner src = new Scanner(System.in);
        int a = src.nextInt();
        LocalDate ld = LocalDate.of(a,3,1);




        LocalDate ld2 = ld.minusDays(1);
        int day = ld2.getDayOfMonth();
        if(day == 29){
            System.out.print("yes");
        }
        else{
            System.out.print("no");
        }
    }

}

发表于 2025-07-06 01:00:44 回复(0)
#include <stdio.h>

int main() {
    int n;
    while(1){
        if(scanf("%d",&n)!=1){
            while(getchar()!='\n');
            continue;
        }
        while(getchar()!='\n');
        if(n < 1 || n > 2018){
            continue;//如果输入错误就重新开始while的循环,直到正确.
        }
        if((n % 400 == 0) || (n % 4 == 0 && n % 100 != 0)){
            printf("yes\n");
        }else{
            printf("no\n");
        }
        break;
    }
    return 0;
}

发表于 2025-07-01 18:02:11 回复(0)
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    if(n%400==0||n%4==0&&n%100!=0)
    {
        printf("yes");
    }
    else {
        printf("no");
    }
    return 0;
}
发表于 2025-06-25 19:46:45 回复(0)
n = int(input())

if n%400==0:
    print("yes")
elif n%4==0 and n%100 != 0:
    print("yes")
else:
    print("no")
发表于 2025-06-17 16:48:32 回复(0)
#include <stdio.h>

int main()
 {
    int n = 0;
    scanf("%d", &n);

    if (n % 400 == 0)
    {
        printf("yes\n");
    }
    else if ( n % 4 == 0 && n % 100 != 0)
    {
        printf("yes\n", n);
    }
    else
    {
        printf("no\n");
    }

    return 0;
}
发表于 2025-06-08 20:58:39 回复(0)
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            if(a % 400 == 0 || (a % 4 ==0)&&(a % 100 !=0)){
                System.out.printf("yes");
            }else{
                System.out.printf("no");
            }
        }
    }
}
发表于 2025-06-06 15:11:09 回复(0)
n = int(input())
if n % 4 == 0 and n % 100 != 0 or n %400 == 0:
    print('yes')
else:
    print('no')
发表于 2025-05-27 09:27:59 回复(0)
a = int(input())
if (a%4==0 and a%100!=0)&nbs***bsp;(a%400==0):
    print("yes")
else:
    print("no")

发表于 2025-04-28 10:37:27 回复(0)
a=int(input())
if (a%4==0 and a%100!=0) or (a%400==0):
    print('yes')
else:
    print('no')

闰年分为普通闰年和世纪闰年,具体判断规则如下:
  • 普通闰年:公历年份是 4 的倍数,且不是 100 的倍数的年份为普通闰年。例如 2004 年能被 4 整除且 不能被 100 整除,所以 2004 年是普通闰年。
  • 世纪闰年:公历年份是 400 的倍数的年份为世纪闰年。例如 2000 年能被 400 整除,所以 2000 年是世纪闰年;而 1900 年不能被 400 整除,虽然它能被 4 整除,但它同时能被 100 整除,所以 1900 年不是闰年。

发表于 2025-02-14 17:31:40 回复(0)