import java.util.Scanner; public class IfYears { public static boolean isleapyear(int year){ if((year%4==0&&year%100!=0)||year%400==0) return true; else return false; } public static void main(String[] args) { System.out.println("请输入要判断的年份: "); Scanner in = new Scanner(System.in); int n = in.nextInt(); if(isleapyear(n)==true) { System.out.println(n+"年为闰年"); } else System.out.println(n+"年不是闰年"); } }
从键盘上读取一个年份,判断是否为闰年(JAVA)
最新推荐文章于 2024-10-05 17:50:03 发布