Hackerrank – Java Date and Time
Hackerrank – Problem Statement A description of the problem can be found on Hackerrank. Solution I created solution in: Java All solutions are also available on my GitHub. Java
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 |
import java.util.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int month = in.nextInt(); int day = in.nextInt(); int year = in.nextInt(); Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month - 1); cal.set(Calendar.DAY_OF_MONTH, day); int weekDay = cal.get(Calendar.DAY_OF_WEEK); String dayName = ""; switch (weekDay) { case Calendar.MONDAY: dayName = "MONDAY"; break; case Calendar.TUESDAY: dayName = "TUESDAY"; break; case Calendar.WEDNESDAY: dayName = "WEDNESDAY"; break; case Calendar.THURSDAY: dayName = "THURSDAY"; break; case Calendar.FRIDAY: dayName = "FRIDAY"; break; case Calendar.SATURDAY: dayName = "SATURDAY"; break; case Calendar.SUNDAY: dayName = "SUNDAY"; break; } System.out.println(dayName); } } |