Skip to content

Instantly share code, notes, and snippets.

@muralidharan-rade
Created August 12, 2020 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muralidharan-rade/4035bf74b7a7e6ffcb66c326f97d3cfa to your computer and use it in GitHub Desktop.
Save muralidharan-rade/4035bf74b7a7e6ffcb66c326f97d3cfa to your computer and use it in GitHub Desktop.
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
class Result {
/*
* Complete the 'findDay' function below.
*
* The function is expected to return a STRING.
* The function accepts following parameters:
* 1. INTEGER month
* 2. INTEGER day
* 3. INTEGER year
*/
public static String findDay(int month, int day, int year) {
Calendar cal = new GregorianCalendar(year, month-1, day); // month - 1 since month from 0
System.out.print(year +":"+ month +":"+ day);
int weekDay = cal.get(Calendar.DAY_OF_WEEK);
String dayWeek = "";
switch(weekDay) {
case 2:
dayWeek = "MONDAY";
break;
case 3:
dayWeek = "TUESDAY";
break;
case 4:
dayWeek = "WEDNESDAY";
break;
case 5:
dayWeek = "THURSDAY";
break;
case 6:
dayWeek = "FRIDAY";
break;
case 7:
dayWeek = "SATURDAY";
break;
case 1:
dayWeek = "SUNDAY";
break;
}
return dayWeek;
}
}
public class UtilDayOfWeek {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
int month = Integer.parseInt(firstMultipleInput[0]);
int day = Integer.parseInt(firstMultipleInput[1]);
int year = Integer.parseInt(firstMultipleInput[2]);
String res = Result.findDay(month, day, year);
System.out.println(res);
bufferedReader.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment