The question asks to calculate the number of 13ths that fall on each day of the week. This is my code.
class CopyOffriday {
public static void main(String[] args
As pointed out in comments, you are iterating for 11 months. I tried this problem after you posted to know if I am missing something. Other than that it looks okay. Let us know if 12 months fixes the problem. Otherwise I'll try looking more into your code.
SPOILER ALERT for my referred code.
HashMap daysInAMonth = new HashMap();
daysInAMonth.put(0, 31);
daysInAMonth.put(2, 31);
daysInAMonth.put(3, 30);
daysInAMonth.put(4, 31);
daysInAMonth.put(5, 30);
daysInAMonth.put(6, 31);
daysInAMonth.put(7, 31);
daysInAMonth.put(8, 30);
daysInAMonth.put(9, 31);
daysInAMonth.put(10, 30);
daysInAMonth.put(11, 31);
HashMap dayFrequency = new HashMap(7);
//sat - 0
// sun -1
// mon -2
// tue -3
// wed -4
// thu -5
// fri -6
dayFrequency.put(0, 0);
dayFrequency.put(1, 0);
dayFrequency.put(2, 0);
dayFrequency.put(3, 0);
dayFrequency.put(4, 0);
dayFrequency.put(5, 0);
dayFrequency.put(6, 0);
int N = Integer.parseInt(st.nextToken());
if (N==0) {
out.println("0 0 0 0 0 0 0");
System.exit(0);
}
System.out.println(N);
int firstFriday = 0;
int lastFriday = 0;
for(int i=0 ;i