首页 > 编程知识 正文

java判断某一年是否为闰年,判断某一个年份是否为闰年

时间:2023-05-04 11:36:11 阅读:215837 作者:4470


闰年的判定规则是:

如果该年能被4整除且不能被100整除,或者能被400整除,则该年是闰年,否则不是


import java.util.Scanner;

public class LeapYear {

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入一个年份:");
long year = scan.nextLong();
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
System.out.println(year + "年是闰年!");
} else {
System.out.println(year + "年是平年!");
}
}

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。