-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem19.java
executable file
·100 lines (84 loc) · 1.67 KB
/
Problem19.java
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import java.util.*;
import java.math.BigInteger;
public class helloworld {
public enum Months {
January,
February,
March,
April,
May,
June,
July,
August,
September,
October,
November,
December;
}
public enum Day {
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday;
}
public static void main(String []args){
//System.out.println("Hello World");
System.out.println("Answer: " + NumSundays());
}
public static int NumSundays() {
Day current = Day.Monday;
int index = 1;
int dayIndex = 0;
int limit = 31;
int numSundays = 0;
for (int i = 1900; i <= 2000; i++) {
System.out.println("YEAR: " + i);
for (Months value: Months.values()) {
limit = GetLimit(i, value);
System.out.println(value.name() + " limit: " + limit);
while (index <= limit) {
current = Day.values()[(dayIndex % 7)];
System.out.println(" " + current.name());
if (i > 1900) {
if (index == 1 && current == Day.Sunday) {
numSundays++;
}
}
index++;
dayIndex = (dayIndex+1);
}
//dayIndex = (current.ordinal() + 1)%7;
index = 1;
}
}
return numSundays;
}
public static int GetLimit(int index, Months value) {
int limit = 0;
if (value == Months.February) {
if (index %100 == 0) {
if (index %400 == 0) {
limit = 29;
}
else
limit = 28;
}
else {
if (index%4==0) {
limit = 29;
}
else
limit = 28;
}
}
else if (value == Months.April || value == Months.June || value == Months.September || value == Months.November) {
limit = 30;
}
else
limit = 31;
return limit;
}
}