We Can print Calendar by using this Program(pass month and year)
class cal
{
int z,zz;
int calc(int x1,int y1)
{
z=x1;
zz=y1;
int mo,n,o=0,oo1=0,l,y;
mo=x1;
y=y1;
n=y-1;
while(n>=400)
{
n=n-400;
}
if(n>=300)
{
n=n-300;
o=1;
}
else if(n>=200)
{
n=n-200;
o=3;
}
else if(n>=100)
{
n=n-100;
o=5;
}
if(n>0)
{
l=n/4;
n=n-l;
oo1=l*2+n;
oo1=oo1%7;
o=o+oo1;
}
if(mo==1)
{
if(o>=7)
o=o%7;
}
else if(mo==2)
{
o=o+31;
if(o>=7)
o=o%7;
}
else if(mo==3&&y%4==0)
{
o=o+31+29;
if(o>=7)
o=o%7;
}
else if(mo==3&&y%4!=0)
{
o=o+31+28;
if(o>=7)
o=o%7;
}
else if(mo==4&&y%4==0)
{
o=o+31+29+31;
if(o>=7)
o=o%7;
}
else if(mo==4&&y%4!=0)
{
o=o+31+28+31;
if(o>=7)
o=o%7;
}
else if(mo==5&&y%4==0)
{
o=o+31+29+31+30;
if(o>=7)
o=o%7;
}
else if(mo==5&&y%4!=0)
{
o=o+31+28+31+30;
if(o>=7)
o=o%7;
}
else if(mo==6&&y%4==0)
{
o=o+31+29+31+30+31;
if(o>=7)
o=o%7;
}
else if(mo==6&&y%4!=0)
{
o=o+31+28+31+30+31;
if(o>=7)
o=o%7;
}
else if(mo==7&&y%4==0)
{
o=o+31+29+31+30+31+30;
if(o>=7)
o=o%7;
}
else if(mo==7&&y%4!=0)
{
o=o+31+28+31+30+31+30;
if(o>=7)
o=o%7;
}
else if(mo==8&&y%4==0)
{
o=o+31+29+31+30+31+30+31;
if(o>=7)
o=o%7;
}
else if(mo==8&&y%4!=0)
{
o=o+31+28+31+30+31+30+31;
if(o>=7)
o=o%7;
}
else if(mo==9&&y%4==0)
{
o=o+31+29+31+30+31+30+31+31;
if(o>=7)
o=o%7;
}
else if(mo==9&&y%4!=0)
{
o=o+31+28+31+30+31+30+31+31;
if(o>=7)
o=o%7;
}
else if(mo==10&&y%4==0)
{
o=o+31+29+31+30+31+30+31+31+30;
if(o>=7)
o=o%7;
}
else if(mo==10&&y%4!=0)
{
o=o+31+28+31+30+31+30+31+31+30;
if(o>=7)
o=o%7;
}
else if(mo==11&&y%4==0)
{
o=o+31+29+31+30+31+30+31+31+30+31;
if(o>=7)
o=o%7;
}
else if(mo==11&&y%4!=0)
{
o=o+31+28+31+30+31+30+31+31+30+31;
if(o>=7)
o=o%7;
}
else if(mo==12&&y%4==0)
{
o=o+31+29+31+30+31+30+31+31+30+31+30;
if(o>=7)
o=o%7;
}
else if(mo==12&&y%4!=0)
{
o=o+31+28+31+30+31+30+31+31+30+31+30;
if(o>=7)
o=o%7;
}
o=o+1;
System.out.println("odd day is "+o);
return o;
}
void pcal(int n)
{
int a,b=0,c=0,d;
a=n;
System.out.println("\n sun mon tue web ths fri sat");
if(z==1||z==3||z==5||z==7||z==8||z==10||z==12)
{
for(d=a,c=1;c<=31;)
{
b++;
if(d!=0)
{
System.out.print(" ");
d--;
}
else
{
if(c<=9)
System.out.print(" ");
System.out.print(" "+c);
c++;
}
if(b==7)
{
System.out.print("\n");
b=0;
}
}
}
if(z==4||z==6||z==9||z==11)
{
for(d=a,c=1;c<=30;)
{
b++;
if(d!=0)
{
System.out.print(" ");
d--;
}
else
{
if(c<=9)
System.out.print(" ");
System.out.print(" "+c);
c++;
}
if(b==7)
{
System.out.print("\n");
b=0;
}
}
}
if(z==2&&zz%4==0)
{
for(d=a,c=1;c<=29;)
{
b++;
if(d!=0)
{
System.out.print(" ");
d--;
}
else
{
if(c<=9)
System.out.print(" ");
System.out.print(" "+c);
c++;
}
if(b==7)
{
System.out.print("\n");
b=0;
}
}
}
if(z==2&&zz%4!=0)
{
for(d=a,c=1;c<=28;)
{
b++;
if(d!=0)
{
System.out.print(" ");
d--;
}
else
{
if(c<=9)
System.out.print(" ");
System.out.print(" "+c);
c++;
}
if(b==7)
{
System.out.print("\n");
b=0;
}
}
}
}
};
class ecal
{
public static void main(String arg[])
{
int x=Integer.parseInt(arg[0]);
int y=Integer.parseInt(arg[1]);
cal c=new cal();
int n=c.calc(x,y);
c.pcal(n);
}
}
Question on Core java for Freshers
class cal
{
int z,zz;
int calc(int x1,int y1)
{
z=x1;
zz=y1;
int mo,n,o=0,oo1=0,l,y;
mo=x1;
y=y1;
n=y-1;
while(n>=400)
{
n=n-400;
}
if(n>=300)
{
n=n-300;
o=1;
}
else if(n>=200)
{
n=n-200;
o=3;
}
else if(n>=100)
{
n=n-100;
o=5;
}
if(n>0)
{
l=n/4;
n=n-l;
oo1=l*2+n;
oo1=oo1%7;
o=o+oo1;
}
if(mo==1)
{
if(o>=7)
o=o%7;
}
else if(mo==2)
{
o=o+31;
if(o>=7)
o=o%7;
}
else if(mo==3&&y%4==0)
{
o=o+31+29;
if(o>=7)
o=o%7;
}
else if(mo==3&&y%4!=0)
{
o=o+31+28;
if(o>=7)
o=o%7;
}
else if(mo==4&&y%4==0)
{
o=o+31+29+31;
if(o>=7)
o=o%7;
}
else if(mo==4&&y%4!=0)
{
o=o+31+28+31;
if(o>=7)
o=o%7;
}
else if(mo==5&&y%4==0)
{
o=o+31+29+31+30;
if(o>=7)
o=o%7;
}
else if(mo==5&&y%4!=0)
{
o=o+31+28+31+30;
if(o>=7)
o=o%7;
}
else if(mo==6&&y%4==0)
{
o=o+31+29+31+30+31;
if(o>=7)
o=o%7;
}
else if(mo==6&&y%4!=0)
{
o=o+31+28+31+30+31;
if(o>=7)
o=o%7;
}
else if(mo==7&&y%4==0)
{
o=o+31+29+31+30+31+30;
if(o>=7)
o=o%7;
}
else if(mo==7&&y%4!=0)
{
o=o+31+28+31+30+31+30;
if(o>=7)
o=o%7;
}
else if(mo==8&&y%4==0)
{
o=o+31+29+31+30+31+30+31;
if(o>=7)
o=o%7;
}
else if(mo==8&&y%4!=0)
{
o=o+31+28+31+30+31+30+31;
if(o>=7)
o=o%7;
}
else if(mo==9&&y%4==0)
{
o=o+31+29+31+30+31+30+31+31;
if(o>=7)
o=o%7;
}
else if(mo==9&&y%4!=0)
{
o=o+31+28+31+30+31+30+31+31;
if(o>=7)
o=o%7;
}
else if(mo==10&&y%4==0)
{
o=o+31+29+31+30+31+30+31+31+30;
if(o>=7)
o=o%7;
}
else if(mo==10&&y%4!=0)
{
o=o+31+28+31+30+31+30+31+31+30;
if(o>=7)
o=o%7;
}
else if(mo==11&&y%4==0)
{
o=o+31+29+31+30+31+30+31+31+30+31;
if(o>=7)
o=o%7;
}
else if(mo==11&&y%4!=0)
{
o=o+31+28+31+30+31+30+31+31+30+31;
if(o>=7)
o=o%7;
}
else if(mo==12&&y%4==0)
{
o=o+31+29+31+30+31+30+31+31+30+31+30;
if(o>=7)
o=o%7;
}
else if(mo==12&&y%4!=0)
{
o=o+31+28+31+30+31+30+31+31+30+31+30;
if(o>=7)
o=o%7;
}
o=o+1;
System.out.println("odd day is "+o);
return o;
}
void pcal(int n)
{
int a,b=0,c=0,d;
a=n;
System.out.println("\n sun mon tue web ths fri sat");
if(z==1||z==3||z==5||z==7||z==8||z==10||z==12)
{
for(d=a,c=1;c<=31;)
{
b++;
if(d!=0)
{
System.out.print(" ");
d--;
}
else
{
if(c<=9)
System.out.print(" ");
System.out.print(" "+c);
c++;
}
if(b==7)
{
System.out.print("\n");
b=0;
}
}
}
if(z==4||z==6||z==9||z==11)
{
for(d=a,c=1;c<=30;)
{
b++;
if(d!=0)
{
System.out.print(" ");
d--;
}
else
{
if(c<=9)
System.out.print(" ");
System.out.print(" "+c);
c++;
}
if(b==7)
{
System.out.print("\n");
b=0;
}
}
}
if(z==2&&zz%4==0)
{
for(d=a,c=1;c<=29;)
{
b++;
if(d!=0)
{
System.out.print(" ");
d--;
}
else
{
if(c<=9)
System.out.print(" ");
System.out.print(" "+c);
c++;
}
if(b==7)
{
System.out.print("\n");
b=0;
}
}
}
if(z==2&&zz%4!=0)
{
for(d=a,c=1;c<=28;)
{
b++;
if(d!=0)
{
System.out.print(" ");
d--;
}
else
{
if(c<=9)
System.out.print(" ");
System.out.print(" "+c);
c++;
}
if(b==7)
{
System.out.print("\n");
b=0;
}
}
}
}
};
class ecal
{
public static void main(String arg[])
{
int x=Integer.parseInt(arg[0]);
int y=Integer.parseInt(arg[1]);
cal c=new cal();
int n=c.calc(x,y);
c.pcal(n);
}
}
Question on Core java for Freshers
No comments:
Post a Comment