Find the number of times every day occurs in a month | Java program to count occurrence of days in a month ; function to find occurrences ; stores days in a week ; Initialize all counts as 4. ; find index of the first day ; number of days whose occurrence will be 5 ; mark the occurrence to be 5 of n - 28 days ; print the days ; Driver function
import java . util . * ; import java . lang . * ; public class GfG { public static void occurrenceDays ( int n , String firstday ) { String [ ] days = new String [ ] { " Monday " , " Tuesday " , " Wednesday " , " Thursday " , " Friday " , " Saturday " , " Sunday " } ; int [ ] count = new int [ 7 ] ; for ( int i = 0 ; i < 7 ; i ++ ) count [ i ] = 4 ; int pos = 0 ; for ( int i = 0 ; i < 7 ; i ++ ) { if ( firstday == days [ i ] ) { pos = i ; break ; } } int inc = n - 28 ; for ( int i = pos ; i < pos + inc ; i ++ ) { if ( i > 6 ) count [ i % 7 ] = 5 ; else count [ i ] = 5 ; } for ( int i = 0 ; i < 7 ; i ++ ) { System . out . println ( days [ i ] + " ▁ " + count [ i ] ) ; } } public static void main ( String argc [ ] ) { int n = 31 ; String firstday = " Tuesday " ; occurrenceDays ( n , firstday ) ; } }