import java.io.*;
class Calendar
{
public static void main(String a[])throws Exception
{
ab obj =new ab();
obj.find();
}
}
class tmp
{
int d,m,y,mo[]={0,31,28,31,30,31,30,31,31,30,31,30,31},cal=0,i;
void input()throws Exception
{
DataInputStream dd= new DataInputStream(System.in);
System.out.println("Enter a day");
d=Integer.parseInt(dd.readLine());
System.out.println("Enter a month");
m=Integer.parseInt(dd.readLine());
System.out.println("Enter a year");
y=Integer.parseInt(dd.readLine());
if(check()==0)
{System.out.println("Wrong date");
System.exit(0);
}
else
{cal=calculate();
System.out.println("Days passed" +" "+cal);
}
}
private int check()
{
int che=1;
if((y<=0)||m>12||d>31||y<=0||m<=0||(leap()==0 &&m==2&&d>28))
che=0;
else
che=1;
return che;
}
private int leap()
{
if(y%100==0)
{
if(y%400==0)
return (1);
return(0);
}
else if(y%4==0)
return (1);
else
return (0);
}
private int calculate()
{
int c=0,i=1;
for(i=1;i<=y;i++)
{
if(leap()==1)
c=c+366;
else
c=c+365;
}
if(leap()==1)
mo[2]=29;
for(i=1;i<m;i++)
c=c+mo[i];
//c=c+d;
//c=c-1;
return c;
}
public void display(int col)
{
String dis[][]=new String [7][7];
dis[0][0]="sun";
dis[0][1]="mon";
dis[0][2]="tue";
dis[0][3]="wed";
dis[0][4]="thu";
dis[0][5]="fri";
dis[0][6]="sat";
int p1=mo[m],sp=1;
int row=1,j;
for (i=1;i<=p1;i++)
{
if(col==0)
row=(row+1)%7;
dis[row][col]=""+i;
col=(col+1)%7;
}
for(i=0;i<7;i++)
{
for(j=0;j<7;j++)
{if(dis[i][j]!=null)
{
System.out.print(dis[i][j]+"\t");
}
else
System.out.print("\t");
}
System.out.println();
}
}
}
class ab extends tmp
{
public void find()throws Exception
{int cal2,cal4;
super.input();
cal2=cal%7;
cal4=(cal2+5)%7;
display(cal4);
}
}
class Calendar
{
public static void main(String a[])throws Exception
{
ab obj =new ab();
obj.find();
}
}
class tmp
{
int d,m,y,mo[]={0,31,28,31,30,31,30,31,31,30,31,30,31},cal=0,i;
void input()throws Exception
{
DataInputStream dd= new DataInputStream(System.in);
System.out.println("Enter a day");
d=Integer.parseInt(dd.readLine());
System.out.println("Enter a month");
m=Integer.parseInt(dd.readLine());
System.out.println("Enter a year");
y=Integer.parseInt(dd.readLine());
if(check()==0)
{System.out.println("Wrong date");
System.exit(0);
}
else
{cal=calculate();
System.out.println("Days passed" +" "+cal);
}
}
private int check()
{
int che=1;
if((y<=0)||m>12||d>31||y<=0||m<=0||(leap()==0 &&m==2&&d>28))
che=0;
else
che=1;
return che;
}
private int leap()
{
if(y%100==0)
{
if(y%400==0)
return (1);
return(0);
}
else if(y%4==0)
return (1);
else
return (0);
}
private int calculate()
{
int c=0,i=1;
for(i=1;i<=y;i++)
{
if(leap()==1)
c=c+366;
else
c=c+365;
}
if(leap()==1)
mo[2]=29;
for(i=1;i<m;i++)
c=c+mo[i];
//c=c+d;
//c=c-1;
return c;
}
public void display(int col)
{
String dis[][]=new String [7][7];
dis[0][0]="sun";
dis[0][1]="mon";
dis[0][2]="tue";
dis[0][3]="wed";
dis[0][4]="thu";
dis[0][5]="fri";
dis[0][6]="sat";
int p1=mo[m],sp=1;
int row=1,j;
for (i=1;i<=p1;i++)
{
if(col==0)
row=(row+1)%7;
dis[row][col]=""+i;
col=(col+1)%7;
}
for(i=0;i<7;i++)
{
for(j=0;j<7;j++)
{if(dis[i][j]!=null)
{
System.out.print(dis[i][j]+"\t");
}
else
System.out.print("\t");
}
System.out.println();
}
}
}
class ab extends tmp
{
public void find()throws Exception
{int cal2,cal4;
super.input();
cal2=cal%7;
cal4=(cal2+5)%7;
display(cal4);
}
}
Comments