
用JAVA程序判断是否为闰年(代码)
第一个JAVA程序,输入年份,判断该年份是否为闰年 下面展示 JAVA代码。 import java.util.Scanner; public class Test { public static void main(String[] args) { //定义变量year int year; //键盘输入 Scanner sc = new Scanner(System.in); year = sc.nextInt(); sc.close(); //判断是否为闰年 if((year % 4 == 0 && year % 100 !=0) || year % 400 == 0) { //如果年份很大,被3200整除还要判断是否能被172800整除 if(year % 3200 == 0 && year % 172800 != 0) { System.out.println(year + " is not a leapyear "); } else System.out.println(year + " is a leapyear "); } else System.out.println(year + " is not a leapyear"); } }
👁️ 阅读量:0
© 版权声明:本文《用JAVA程序判断是否为闰年(代码)》内容均为本站精心整理或网友自愿分享,如需转载请注明原文出处:https://www.zastudy.cn/wen/1686862349a358192.html。