I did a simple example in hackerrank.com which asks us to return the day of a given date. ex: If the date is 08 05 2015(month day year) it should return WEDNESDAY.
This is the code I wrote for this task
public static String getDay(String day, String month, String year) {
String[] dates=new String[]{"SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY"};
Calendar cal=Calendar.getInstance();
cal.set(Integer.valueOf(year),Integer.valueOf(month),Integer.valueOf(day));
int date_of_week=cal.get(Calendar.DAY_OF_WEEK);
return dates[date_of_week-1];
}
My code returns 'Saturday' for the given example which should be 'Wednesday'. For the current date which is 10 29 2017, it returns 'Wednesday'. Could anyone please help me to solve this issue?