Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”

Leap years are judged by the following rules:

(1) A year that is divisible by 4 but not by 100 is a leap year.

(2) If a year is divisible by 400, it is a leap year.

package csdncom.tt;

import java.util.Scanner;

/** * Created by Administrator on 2021/10/30. */
public class LeapYear {
	public static boolean isLeapYear(int year) {
		return ((year % 4= =0 && year % 100! =0) || year % 400= =0);
	}

	/ * * *@param args
	 */
	public static void main(String[] args) {
		System.out.print("Please enter the year to query [integer]:");

		Scanner input = new Scanner(System.in);

		int year;
        // Get keyboard input
		if (input.hasNextInt()) {
			year = input.nextInt();
		} else {
			System.out.println("Input data format is not correct!");
			System.exit(0);
		}
		if (isLeapYear(2000)) {
			System.out.println(It's a leap year.);
		} else {
			System.out.println("Not a leap year."); }}}Copy the code