-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfhfd.java
More file actions
105 lines (54 loc) · 2.45 KB
/
Copy pathfhfd.java
File metadata and controls
105 lines (54 loc) · 2.45 KB
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
101
102
103
104
105
import java.util.Calendar;
import java.util.GregorianCalendar;
public class fhfd {
public static void main(String[] args) {
// TODO Auto-generated method stub
int Year, Month;
// Assign starting values
Year = 2010;
Month = 0;
// Call method to print the month for the values
printCalendar(Year, Month);
}
public static void printCalendar(int year, int month) {
// Declare variables
int leap_year;
int dayOfWeek=1;
String space = " ";
String[] monthName = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
int[] calDays = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
Calendar cal = new GregorianCalendar(year, month, 1);
System.out.println("Year: " + year + space + "Month: " + monthName[month] + "\n");
System.out.println("S M T W T F S\n");
// Following loop will find out where to print the first day of the month
// dayCounter represents current day of the month and dayOfWeek represents the day of the
// week where 1 is Sunday
for (int dayCounter=1; dayCounter <= calDays[month]; dayCounter++) {
if (dayCounter > 9) {
// This controls the printing of the spaces between the days so it's pretty
space = " ";
}
// This if will find out print out spaces until the day the first of the
// month falls on
if (dayCounter == 1) {
while (dayOfWeek != cal.get(Calendar.DAY_OF_WEEK)) {
System.out.print(space + " ");
dayOfWeek++;
}
// Now we have found the right place to print the first day of the month
System.out.print(dayCounter + space);
dayOfWeek++;
} else {
if (dayOfWeek == 8) {
System.out.print("\n" + dayCounter + space);
dayOfWeek=2;
} else {
// this prints out the current day number and increments j
System.out.print(dayCounter + space);
dayOfWeek++;
}
}
}
System.out.println("\n");
}
}