-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq19.java
More file actions
49 lines (42 loc) · 844 Bytes
/
q19.java
File metadata and controls
49 lines (42 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.*;
import helpers.month;
public class q19 {
public static void main(String[] args) {
int daysPerMonth[] = {31,28,31,30,31,30,31,31,30,31,30,31};
int result = 0;
int numDays = 365 * 100;
int currMonth = 0;
int currDay = 1;
int currYear = 1901;
while(numDays > 0){
int d = daysPerMonth[currMonth];
if(currMonth == 1 && isLeapYear(currYear) > 0){
d++;
numDays++;
}
currDay = (currDay + (d % 7)) % 7;
numDays = numDays - daysPerMonth[currMonth];
++currMonth;
if(currDay == 6)
++result;
if(currMonth > 11){
currMonth = 0;
++currYear;
}
}
System.out.println(result);
}
public static int isLeapYear(int year){
if(year%400 == 0){
return 1;
}
if(year%100 == 0){
return 0;
}
if(year%4 == 0){
return 1;
}else{
return 0;
}
}
}