提示:需要知道闰年平年的概念。需要知道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");
            }
        }
    }
}

 结果展示:

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

 

相关文章:

  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2021-11-28
  • 2021-10-04
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2021-11-28
  • 2021-11-19
相关资源
相似解决方案