用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/dvjo 著作权归作者所有。请勿转载和采集!