I need the code to take a date in the format mm dd yyyy (via standard input) and output the week day in plain English.
Sample input (mm dd yyyy): 09 23 2016
Expected output: FRIDAY
Incorrect output: SUNDAY
Can anyone please explain what's going wrong here? Thank you.
import java.io.*;
import java.util.*;
import java.time.*;
public class DateToDay {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int month = Integer.parseInt(in.next());
int day = Integer.parseInt(in.next());
int year = Integer.parseInt(in.next());
if ((year > 2000) && (year < 3000)) {
Calendar cal = Calendar.getInstance();
Locale locale = Locale.getDefault();
cal.set(Calendar.MONTH, month);
cal.set(Calendar.DAY_OF_MONTH, day);
cal.set(Calendar.YEAR, year);
System.out.println(cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, locale).toUpperCase());
}
else {
System.out.println("Invalid date entered.");
}
}
}