Add tags

Add tags to the following comment
素直にやってみました。

実行結果
-------
A.D. 1900: false
A.D. 2000: true
A.D. 2008: true
A.D. 2009: false
A.D. 2100: false
-------
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
public class LeapYear {
    public static void main(String[] args) {
        System.out.println("A.D. 1900: " + isLeapYear(1900));
        System.out.println("A.D. 2000: " + isLeapYear(2000));
        System.out.println("A.D. 2008: " + isLeapYear(2008));
        System.out.println("A.D. 2009: " + isLeapYear(2009));
        System.out.println("A.D. 2100: " + isLeapYear(2100));
    }

    public static boolean isLeapYear(int aYear) {
        return isDivisible(aYear, 4) ? (isDivisible(aYear, 100) ? (isDivisible(aYear, 400) ? true : false) : true) : false;
    }

    public static boolean isDivisible(int aLeft, int aRight) {
        while (aLeft >= aRight) {
            aLeft -= aRight;
        }
        return aLeft == 0;
    }
}

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...