WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 43 additions & 16 deletions Java/Introduction/Java Date and Time/Solution.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}