We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I could solve it be leveraing Java8 date API and just adjusting the days difference for 1918 year(13 days difference) and pre 1918 year (leap year as my base calendar in geogrian)
publicstaticStringsolve(intyear){DateTimeFormatterformatter=DateTimeFormatter.ofPattern("dd.MM.yyyy");// for all cases after 1918 as I am starting from 1st day of yearintdaysToAdjust=255;if(year==1918){// this is the year they turned to gregorian calendardaysToAdjust=daysToAdjust+13;}elseif(year<1918){// jullian calendar only divide by 4 for leap year, where as gregorian excludes divide by 100 caseif(year%4==0&&year%100==0){daysToAdjust=daysToAdjust-1;}}LocalDatedate=LocalDate.of(year,1,1);LocalDatedayOfProgrammer=date.plusDays(daysToAdjust);returndayOfProgrammer.format(formatter);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day of the Programmer
You are viewing a single comment's thread. Return to all comments →
I could solve it be leveraing Java8 date API and just adjusting the days difference for 1918 year(13 days difference) and pre 1918 year (leap year as my base calendar in geogrian)