-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalendar.java
More file actions
82 lines (64 loc) · 1.5 KB
/
Copy pathCalendar.java
File metadata and controls
82 lines (64 loc) · 1.5 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
package datastructures;
import java.util.GregorianCalendar;
import bridgelabz.utility;
public class Calendar
{
private static int Day_of_Week;
public static void printCalendar(int year,int month)
{
int Leapyear;
int dayOfWeek=1;
String space=" ";
//month number starts from 0-11
String []monthName= {"january","feb","march","April","May","June","july","August","Sep","oct","Nov","Dec"};
int []calDays= {31,28,31,30,31,30,31,31,30,31,30,31};
GregorianCalendar cal=new GregorianCalendar(year,month,1);
if(year%100==0)
if(year%400==0)
{
calDays[1]=28;
}
else if(year%4==0)
{
calDays[1]=29;
}
System.out.println("year: "+ year + space + "month:"+monthName[month]+"\n");
//day number starts from 1 -7
System.out.println(" S M T W TH F SA \n");
for(int daycounter=1;daycounter<=calDays[month];daycounter++);
int daycounter = 0;
if(daycounter>9)
{
space=" ";
}
if(daycounter==1)
{
while(dayOfWeek!=cal.get(Calendar.Day_of_Week))
{
System.out.println(space+ " ");
dayOfWeek++;
}
}
else
{
if(dayOfWeek==8)
{
System.out.println("\n"+ daycounter + space);
dayOfWeek=2;
}
else
{
System.out.println(daycounter + space);
dayOfWeek++;
}
}
}
public static void main(String[] args)
{
System.out.println("enter the year");
int year=utility.getint();
System.out.println("enter the month number");
int month=utility.getint();
printCalendar(year,month);
}
}