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");
            }
        }
    }
}

 結果展示:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM