Java 判断闰年程序:输入出生日期,判断是否为闰年
import java.util.Scanner;
public class LeapYearChecker {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print('请输入出生年份:');
int year = sc.nextInt();
System.out.print('请输入出生月份:');
int month = sc.nextInt();
System.out.print('请输入出生日期:');
int day = sc.nextInt();
if (isLeapYear(year)) {
System.out.println(year + '年是闰年');
} else {
System.out.println(year + '年不是闰年');
}
}
public static boolean isLeapYear(int year) {
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
return true;
} else {
return false;
}
}
}
// 示例输出: // 请输入出生年份:2000 // 请输入出生月份:1 // 请输入出生日期:1 // 2000年是闰年
原文地址: https://www.cveoy.top/t/topic/nFPV 著作权归作者所有。请勿转载和采集!