Find the first day of a given year from a base year having first day as Monday | Java program to implement the above approach ; Function to find the day of 1 st January of Y year ; Count years between years Y and B ; Count leap years ; Non leap years ; Total number of days in the years lying between the years Y and B ; Actual day ; Driver code
import java . util . * ; class GFG { static void findDay ( int Y , int B ) { int lyear , rest , totaldays , day ; Y = ( Y - 1 ) - B ; lyear = Y / 4 ; rest = Y - lyear ; totaldays = ( rest * 365 ) + ( lyear * 366 ) + 1 ; day = ( totaldays % 7 ) ; if ( day == 0 ) System . out . println ( " Monday " ) ; else if ( day == 1 ) System . out . println ( " Tuesday " ) ; else if ( day == 2 ) System . out . println ( " Wednesday " ) ; else if ( day == 3 ) System . out . println ( " Thursday " ) ; else if ( day == 4 ) System . out . println ( " Friday " ) ; else if ( day == 5 ) System . out . println ( " Saturday " ) ; else if ( day == 6 ) System . out . println ( " Sunday " ) ; else System . out . println ( " INPUT ▁ YEAR ▁ IS ▁ WRONG ! " ) ; } public static void main ( String [ ] args ) { int Y = 2020 , B = 1900 ; findDay ( Y , B ) ; } }