The problem
Zeller’s congruence is an algorithm developed by Christian Zeller to calculate the day of the week. See here for formula. Note that the division in the formula performs an integer division. Write a program that prompts the user to enter a year, month, and day of the month, and displays the name of the day of the week. Here are some sample runs:
Enter year: (e.g., 2012): 2015
Enter month: 1-12: 1
Enter the day of the month: 1-31: 25
Day of the week is Sunday
Breaking it down
public static final String dayOfWeekisString = "Day of the week is ";
public static void main(String[] strings) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a year: ");
int year = input.nextInt();
System.out.print("Enter a month: 1-12: ");
int month = input.nextInt();
System.out.print("Enter the day of the month: ");
int dayOfMonth = input.nextInt();
input.close();
LocalDate date = LocalDate.of(year, Month.of(month), dayOfMonth);
DayOfWeek dayOfWeek = date.getDayOfWeek();
System.out.println(dayOfWeekisString + dayOfWeek);
}
Output
Enter a year: 1988
Enter a month: 1-12: 3
Enter the day of the month: 2
Day of the week is WEDNESDAY