diff --git a/Java/Introduction/Java Date and Time/Solution.java b/Java/Introduction/Java Date and Time/Solution.java index 5ae2f4a..17d3e61 100644 --- a/Java/Introduction/Java Date and Time/Solution.java +++ b/Java/Introduction/Java Date and Time/Solution.java @@ -1,19 +1,46 @@ -import java.util.Scanner; -import java.time.LocalDate; +import java.io.*; +import java.util.Calendar; +import java.util.Locale; -public class Solution { - - public static String getDay(String day, String month, String year) { - LocalDate date = LocalDate.of(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day)); - return date.getDayOfWeek().name(); +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 calendar = Calendar.getInstance(); + calendar.set(Calendar.YEAR, year); + calendar.set(Calendar.MONTH, month - 1); // Calendar months are zero-based + calendar.set(Calendar.DAY_OF_MONTH, day); + + return calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.ENGLISH).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)); +} + +public class Solution { + public static void main(String[] args) throws IOException { + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); + + 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); + + bufferedWriter.write(res); + bufferedWriter.newLine(); + + bufferedReader.close(); + bufferedWriter.close(); } -} \ No newline at end of file +}