Java Code for calculating Leap Year

前端 未结 20 2253
执念已碎
执念已碎 2020-11-22 16:30

I am following \"The Art and Science of Java\" book and it shows how to calculate a leap year. The book uses ACM Java Task Force\'s library.

Here is the code the boo

20条回答
  •  隐瞒了意图╮
    2020-11-22 17:02

    If you are using java8 :

    java.time.Year.of(year).isLeap()
    

    Java implementation of above method:

    public static boolean isLeap(long year) {
            return ((year & 3) == 0) && ((year % 100) != 0 || (year % 400) == 0);
        }
    

提交回复
热议问题