/home/caleb/ASDV-Java/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/DayOfTheWeek.java |
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java
package com.calebfontenot.mp2_calebfontenot;
import java.util.Scanner;
public class DayOfTheWeek {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int dayOfTheWeek,
dayOfTheMonth,
century,
yearOfTheCentury,
month,
year;
String weekDay = "nullDay";
System.out.print("Enter year: (e.g., 2022): ");
year = input.nextInt();
System.out.print("Enter month: 1-12: ");
month = input.nextInt();
System.out.print("Enter day of the month: 1-31: ");
dayOfTheMonth = input.nextInt();
century = (year / 100);
yearOfTheCentury = year % 100;
dayOfTheWeek = ((dayOfTheMonth + ((26 * (month + 1)) / 10) + yearOfTheCentury + (yearOfTheCentury / 4) + (century / 4) + (5 * century)) % 7);
System.out.println(dayOfTheWeek);
switch (dayOfTheWeek) {
case 0:
weekDay = "Saturday";
break;
case 1:
weekDay = "Sunday";
break;
case 2:
weekDay = "Monday";
break;
case 3:
weekDay = "Tuesday";
break;
case 4:
weekDay = "Wednesday";
break;
case 5:
weekDay = "Thursday";
break;
case 6:
weekDay = "Friday";
break;
}
System.out.println("Day of the week is " + weekDay);
}
}