java判断闰年

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hju22/article/details/83422805

java判断闰年

能被4整除但不能被100整除或者能被400整除的年份是闰年。

package com.word.word;

import java.util.Scanner;

public class LeapYear {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入年份");
        int year;
        for (int i=0;i<3;i++) {
            year=sc.nextInt();
            if(year%4==0&&year%100!=0||year%400==0){
                System.out.println(year+"是闰年");
            }else{
                System.out.println(year+"不是闰年");
            }
        }
        sc.close();
    }
}

结果:
坚持比努力更重要

猜你喜欢

转载自blog.csdn.net/hju22/article/details/83422805