HackerRank Java- Date and Time




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



  1. import java.io.*;
  2. import java.math.*;
  3. import java.security.*;
  4. import java.text.*;
  5. import java.util.*;
  6. import java.util.concurrent.*;
  7. import java.util.function.*;
  8. import java.util.regex.*;
  9. import java.util.stream.*;
  10. import static java.util.stream.Collectors.joining;
  11. import static java.util.stream.Collectors.toList;
  12. import java.util.stream.*;
  13. import static java.util.stream.Collectors.joining;
  14. import static java.util.stream.Collectors.toList;
  15. import java.time.LocalDate;
  16. class Result {
  17. /*
  18. * Complete the 'findDay' function below.
  19. *
  20. * The function is expected to return a STRING.
  21. * The function accepts following parameters:
  22. * 1. INTEGER month
  23. * 2. INTEGER day
  24. * 3. INTEGER year
  25. */
  26. public static String findDay(int month, int day, int year) {
  27. int d = Integer.valueOf(day);
  28. int m = Integer.valueOf(month);
  29. int y = Integer.valueOf(year);
  30. LocalDate date = LocalDate.of(y, m, d);
  31. return date.getDayOfWeek().toString();
  32. }
  33. }
  34. public class Solution {
  35. public static void main(String[] args) throws IOException {
  36. BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
  37. BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
  38. String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
  39. int month = Integer.parseInt(firstMultipleInput[0]);
  40. int day = Integer.parseInt(firstMultipleInput[1]);
  41. int year = Integer.parseInt(firstMultipleInput[2]);
  42. String res = Result.findDay(month, day, year);
  43. bufferedWriter.write(res);
  44. bufferedWriter.newLine();
  45. bufferedReader.close();
  46. bufferedWriter.close();
  47. }
  48. }
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


donate a cup of tea :)


Join Our Facebook Group

Share this solution






codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube