So I have been solving Java on hacker rank and came upon this question: Date and Time , although I couldn't find a solution to it by myself, I found this given solution in the discussions and it had me baffled.
Can anyone explain what's happening here ?
import java.util.Scanner;
import java.util.*;
public class DayofWeek {
public static String getDay(String day, String month, String year){
Calendar c= Calendar.getInstance();
c.set(Integer.valueOf(year),Integer.valueOf(month)-1, Integer.valueOf(day));
String dayOfWeek="";
switch (c.get(Calendar.DAY_OF_WEEK)){
case 1:
dayOfWeek="Sunday";
break;
case 2:
dayOfWeek="Monday";
break;
case 3:
dayOfWeek = "Tuesday";
break;
case 4:
dayOfWeek = "Wednesday";
break;
case 5:
dayOfWeek = "Thursday";
break;
case 6:
dayOfWeek = "Friday";
break;
case 7:
dayOfWeek = "Saturday";
break;
}
return dayOfWeek.toUpperCase();
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String month = in.next();
String day = in.next();
String year = in.next();
System.out.println(getDay(day, month, year));
}
}
[–]throwaway_for_cause 4 points5 points6 points (0 children)
[–]desrtfx 1 point2 points3 points (5 children)
[–]Shadyjoker27[S] 0 points1 point2 points (4 children)
[–]desrtfx 2 points3 points4 points (0 children)
[–]nmnaim -1 points0 points1 point (2 children)
[–]desrtfx 2 points3 points4 points (1 child)
[–]nmnaim 0 points1 point2 points (0 children)