• + 0 comments

    java(8)

    public static String dayOfProgrammer(int year) {
        // Write your code here
    
        int[] leapYear = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        int[] notLeapYear = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    
        int month = 0;
        int sumOfDay = 0;
    
        if (year < 1919) {
    
            if (year % 4 == 0) {
    
                while (sumOfDay <= 256) {
    
                    sumOfDay += leapYear[month];
                    month++;
    
                }
                if (sumOfDay > 256) {
                    sumOfDay -= leapYear[month - 1];
                }
            } else if (year % 4 != 0) {
    
                while (sumOfDay <= 256) {
    
                    sumOfDay += notLeapYear[month];
                    month++;
                }
                if (sumOfDay > 256) {
                    sumOfDay -= notLeapYear[month - 1];
                }
    
            }
    
        }
    
        else if (year > 1918) {
            if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
                while (sumOfDay <= 256) {
    
                    sumOfDay += leapYear[month];
                    month++;
                }
                if (sumOfDay > 256) {
                    sumOfDay -= leapYear[month - 1];
                }
    
            } else {
    
                while (sumOfDay <= 256) {
    
                    sumOfDay += notLeapYear[month];
                    month++;
                }
                if (sumOfDay > 256) {
                    sumOfDay -= notLeapYear[month - 1];
                }
    
            }
        }
    
        int date = 256 - sumOfDay;
    
        String m;
        if (month < 12) {
            String fL = "0";
            m = fL + Integer.toString(month);
        } else {
            m = Integer.toString(month);
        }
        String d = Integer.toString(date);
        String y = Integer.toString(year);
    
        return d + "." + m + "." + y;
    
    }