Java之判断2000~2023年有哪些年份是闰年并打印输出
目录
- Java判断2000~2023年哪些年份是闰年
- Java实现2000年到3000年之间的所有闰年
- 总结
Java判断2000~2023年哪些年份是闰年
package com.niu.jk;
public class demo_2 {
public static void main(String[] args) {
int year = 0;
for (year = 2000; year <php= 2023; ++year) {
if ((year % 4 =编程客栈= 0 && year % 100 != 0) || (year % 400 == 0)) {
System.out.printf("%d", year);
System.out.println();
}
}
}
}
输出的效果如图所示:

Java实现2000年到3000年之间的所有闰年
判断是不是闰年 2000–3000
package com.shipeiqi.yingyong;
public class ClassP6 {
static int LeapYear(int year){
if((yeandroidar%400 == 0) || (year%100!=0)&& (year%4==0)){
return 1; //是闰年,则返回1
编程客栈 }else{
return 0; //不是闰年,则返回0
}
}
public static void main(String[] args) {
int year;
int count = 0;
System.out.println("2000年到3000年");
for(y编程ear = 2000;year<=3000;year++){
if(LeapYear(year) == 1){
System.out.println(year+"");
count++;
if(count%16 == 0){
System.out.print("\n");
}
}
}
System.out.print("\n");
}
}
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程客栈(www.devze.com)。
加载中,请稍侯......
精彩评论