java--判断某一年是闰年还是平年

提示:需要知道闰年平年的概念。需要知道java的基本语法规则。

package studying;

import java.util.Scanner;

public class JudgmentYear {
    
    /*
     * Determine whether the year entered is common or leap years?
     */
    
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        for(int i = 0; ; i++) {
            System.out.println("Please enter year:");
            int year = input.nextInt();
            if(year % 4 != 0 || year % 100 == 0 && year % 400 != 0) {
                System.out.println(year + " is common year");
            }else {
                System.out.println(year + " is leap year");
            }
        }
    }
}

 结果展示:

 

posted @ 2017-12-19 19:31  superdrew  阅读(4253)  评论(0编辑  收藏  举报