Java实现:P5711 【深基3.例3】闰年判断

在这里插入图片描述
在这里插入图片描述

import java.io.IOException;
import java.util.Scanner;

public class Main {
    
    
	@SuppressWarnings("resource")
	public static void main(String[] args) throws IOException{
    
    
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		if((n%4==0&&n%100!=0)||n%400==0) {
    
    
			System.out.println(1);
		}else {
    
    
			System.out.println(0);
		}
	}
}
  • 闰年判断条件:能被400整除或者能被四整除但不能被100整除
    附蓝桥杯练习代码(其实就是把0和1换成yes和no,注意大小写就够了):
import java.io.IOException;
import java.util.Scanner;

public class Main {
    
    
	@SuppressWarnings("resource")
	public static void main(String[] args) throws IOException{
    
    
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		if((n%4==0&&n%100!=0)||n%400==0) {
    
    
			System.out.println("yes");
		}else {
    
    
			System.out.println("no");
		}
	}
}

猜你喜欢

转载自blog.csdn.net/jinyeran/article/details/115133498