zoukankan      html  css  js  c++  java
  • 闰年判断

     
    package com.liaojianya.chapter1;
    
    import java.util.Scanner;
    
    /**
     * This program demonstrates the way of judging leap year.
     * @author LIAO JIANYA
     * 2016年7月19日
     */
    public class LeapYear
    {
    	public static void main(String[] args)
    	{
    		@SuppressWarnings("resource")
    		Scanner scan = new Scanner(System.in);
    		System.out.println("Please enter the year: ");		
    		int year = (int)scan.nextInt();
    		if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
    		{
    			System.out.println(year + " is leap year!");
    		}
    		else
    		{
    			System.out.println(year + " is not leap year!");
    		}
    	}
    
    }
    

      

      运行结果1:

    Please enter the year: 
    2004
    2004 is leap year!
    

      运行结果2:

    Please enter the year: 
    2017
    2017 is not leap year!
    

      运行结果3:

    Please enter the year: 
    4000
    4000 is leap year!

      分析:

      判断闰年一般的规律为: 四年一闰,百年不闰,四百年再闰.

      其简单计算方法:1.能被4整除而不能被100整除.(如2016年就是闰年,1800年不是.)

              2.能被400整除.(如2000年和4000年都是闰年)

  • 相关阅读:
    Go语言http之请求接收和处理 代码
    C++之IO流的状态以及使用
    C++之指向函数的指针
    C++之数组类型的形参
    C++之vector类型的形参
    C++之形参
    C++之运算符
    C++之多维数组
    C++之动态数组
    C++之指针
  • 原文地址:https://www.cnblogs.com/Andya/p/5683913.html
Copyright © 2011-2022 走看看