学习记录16

判断闰年import java.util.Scanner;

public class LeapYearChecker {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入一个年份: ");
int year = scanner.nextInt();

    if (isLeapYear(year)) {
        System.out.println(year + " 年是闰年。");
    } else {
        System.out.println(year + " 年不是闰年。");
    }
    scanner.close();
}

public static boolean isLeapYear(int year) {
    // 普通年份能被 4 整除但不能被 100 整除
    boolean condition1 = (year % 4 == 0) && (year % 100 != 0);
    // 世纪年份能被 400 整除
    boolean condition2 = year % 400 == 0;

    return condition1 || condition2;
}

}

posted @   吉尼泰梅  阅读(1)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示