Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Java Date and Time Solution and Updated Readme #122

Merged
merged 1 commit into from Oct 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 60 additions & 0 deletions Java/Introduction/DateTime.java
@@ -0,0 +1,60 @@
// Problem - https://www.hackerrank.com/challenges/java-date-and-time/problem?isFullScreen=true
// Score - 15
// Difficulty - Easy

import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
import java.util.Calendar;
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 import java.util.Calendar; import java.util.Calendar;
*/

public static String findDay(int month, int day, int year) {
Calendar cal=Calendar.getInstance();
String dd[]={"SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY"};
cal.set(year,month-1,day);
int n=cal.get(Calendar.DAY_OF_WEEK);
return dd[n-1];
}

}

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();
}
}
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -181,6 +181,7 @@
| S.No. | Problem | Solution | Score | Difficulty |
|--|--|--|--|--|
| 1 | [Java Stdin and Stdout](https://www.hackerrank.com/challenges/java-stdin-stdout/problem) | [Solution]() | 10 | Easy |
| 2 | [Java Date and Time](https://www.hackerrank.com/challenges/java-date-and-time/problem?isFullScreen=true) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/Java/Introduction/DateTime.java) | 15 | Easy |

### Strings
| S.No. | Problem | Solution | Score | Difficulty |
Expand Down