-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDayoftheProgrammer.java
More file actions
49 lines (44 loc) ยท 1.59 KB
/
DayoftheProgrammer.java
File metadata and controls
49 lines (44 loc) ยท 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package hackerrank;
public class DayoftheProgrammer {
static String dayOfProgrammer(int year) {
//sol 1
/*
//์จ๋ฆฌ์ฐ์ค์ ์ค๋
if(year >= 1700 && year <= 1917 && year%4 == 0){
return "12.09."+year;
}else if(year == 1918){
return "26.09."+year;
}
//๊ทธ๋ ๊ณ ๋ฆฌ๋ ฅ์ ์ค๋
if(year%4 == 0 && year%100 == 0 && year%400 == 0){
return "12.09."+year;
//ํ๋
}else if(year%4 == 0 && year%100 == 0) {
return "13.09."+year;
//๊ทธ๋ ๊ณ ๋ฆฌ๋ ฅ์ ์ค๋
}else if(year%4 == 0 && year%100 != 0){
return "12.09."+year;
}
//ํ๋
return "13.09."+year;
*/
//sol2
String date = "";
if(year < 1918) { //Julian check for leap year
date += (year % 4 == 0) ? "12.09." + year : "13.09." + year;
} else if(year == 1918) { //Special case: transition year
date += "26.09." + year;
} else { //Gregorian check for leap year
date += ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) ? "12.09." + year : "13.09." + year;
}
return date;
}
public static void main(String[] args) {
System.out.println(dayOfProgrammer(2017)+", ans: 13.09.2017");
System.out.println(dayOfProgrammer(2016)+", ans: 12.09.2016");
System.out.println(dayOfProgrammer(1800)+", ans: 12.09.1800");
System.out.println(dayOfProgrammer(2100)+", ans: 13.09.2100");
System.out.println(dayOfProgrammer(2000)+", ans: 12.09.2000");
System.out.println(dayOfProgrammer(1918)+", ans: 26.09.1918");
}
}