public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入年份:");
String line = sc.nextLine();
//将录入的字符串转换为数字
int year = Integer.parseInt(line);
boolean b = getYear(year);
System.out.println(b);
}
private static boolean getYear(int year) {
Calendar c = Calendar.getInstance();
//设置那一年为3月1日
c.set(year, 2, 1);
//将日期向前减一
c.add(Calendar.DAY_OF_MONTH, -1);
//判断是否为29天
return c.get(Calendar.DAY_OF_MONTH)==29;
} |