From 2703d130b50ff417a3bf08a8af348b2f6e1d775f Mon Sep 17 00:00:00 2001 From: Mohit Date: Mon, 24 Jan 2022 22:36:00 +0530 Subject: [PATCH 1/2] Create DATEANDTIME.java --- Java/Introduction/DATEANDTIME.java | 67 ++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 Java/Introduction/DATEANDTIME.java diff --git a/Java/Introduction/DATEANDTIME.java b/Java/Introduction/DATEANDTIME.java new file mode 100644 index 0000000..810e0ba --- /dev/null +++ b/Java/Introduction/DATEANDTIME.java @@ -0,0 +1,67 @@ +/** + * The Calendar class is an abstract class that provides methods for converting between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR, and so on, and for manipulating the calendar fields, such as getting the date of the next week. + *

+ * You are given a date. You just need to write the method, , which returns the day on that date. To simplify your task, we have provided a portion of the code in the editor. + *

+ * For example, if you are given the date , the method should return as the day on that date. + *

+ * image + *

+ * Input Format + *

+ * A single line of input containing the space separated month, day and year, respectively, in format. + *

+ * Constraints + *

+ * Output Format + *

+ * Output the correct day in capital letters. + *

+ * Sample Input + *

+ * 08 05 2015 + * Sample Output + *

+ * WEDNESDAY + * Explanation + *

+ * The day on August th was WEDNESDAY. + */ +import java.io.*; +import java.util.*; +import java.time.LocalDate; +public class DATEANDTIME +{ +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[] MultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" "); + + int month = Integer.parseInt(MultipleInput[0]); + + int day = Integer.parseInt(MultipleInput[1]); + + int year = Integer.parseInt(MultipleInput[2]); + + String res = FIND_DAY.findDay(month, day, year); + + bufferedWriter.write(res); + bufferedWriter.newLine(); + + bufferedReader.close(); + bufferedWriter.close(); +} +} +class FIND_DAY{ + + public static String findDay(int month, int day, int year) { + Calendar c = Calendar.getInstance();//creating instance of abstract class calender + c.set(year, month, day);//calender format is set to yyyy-mm-dd + return LocalDate.of(year, month, day).getDayOfWeek().toString();//we are using LocalDate Class (immutable)with format set to yyyymmdd using method LocalDate.of(int,int,int) + + + } + +} From 558c420ceb5bd36d6fdffd4631777b54ec9c660d Mon Sep 17 00:00:00 2001 From: Mohit Date: Mon, 24 Jan 2022 22:38:52 +0530 Subject: [PATCH 2/2] Update DATEANDTIME.java Test Knowledge of Calendar Class in Collection Framework --- Java/Introduction/DATEANDTIME.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Java/Introduction/DATEANDTIME.java b/Java/Introduction/DATEANDTIME.java index 810e0ba..fda9667 100644 --- a/Java/Introduction/DATEANDTIME.java +++ b/Java/Introduction/DATEANDTIME.java @@ -1,3 +1,4 @@ +Knowledge of Calender Class in Java /** * The Calendar class is an abstract class that provides methods for converting between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR, and so on, and for manipulating the calendar fields, such as getting the date of the next week. *