Posts

Showing posts from February 10, 2014

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…