Skip to main content

print month of any year as inputted by the user in java

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);

}
}

Comments

Popular posts from this blog

PROGRAM TO PRINT COLOURS OF RAINBOW ACCORDING TO THE NO. INPUTTED BY THE USER

#include,stdio.h> #include<conio.h> void main() { int ch; printf("INPUT A NUMBER\n"); scanf("%d",&ch); switch(ch) { case 6: printf("Red"); break; case 5 : printf(" Orange"); break; case 4 : printf(" Yellow"); break; case 3 : printf(" Green"); break; case 2 : printf(" Blue"); break; case 1 : printf(" Indigo"); break; case 0 : printf(" Violet"); break; default : ("wrong input "); } } SIMPLE PROGRAMS FIND TYPE OF THE TRIANGLE TEMPERATURE CONVERSION COMMISSION OF A SALESMAN PRINT NUMBERS IN DESCENDING ORDER BIGGEST NUMBER AMONG THREE NUMBERS CALCULATE DIVISION A YEAR IS LEAP OR NOT A NUMBER IS ODD OR EVEN PRINT THE SQUARE ROOT ELSE PRINT N TO THE POWER 5 PRINT A NEW NUMBER BY ADDING 1 TO EACH DIGIT OF THE NUMBER PRINT THE NO. OF CURRENCY NOTES ACCORDING TO THE AMOUNT ENTERED DATA STRUCTURES ENTER DETAILS OF A STUDENT ENTER DETAILS OF A ST...

unix commands

 

Baby doge paws

Baby doge paws link 🎉 Join the BabyDoge PAWS Clicker adventure! Solve challenges, join daily events, and invite friends. Stay tuned for the token airdrop! 🐾 🌟 Earn 10k PAWS as a welcome bonus 🌟 Get 25k PAWS with Telegram Premium https://t.me/BabyDogePAWS_Bot?start=r_6394860582