For Details of The Program: CLICK HERE
import java.io.*;
class A
{
int days[]={31,28,31,30,31,30,31,31,30,31,30,31};
String mon[]={"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"};
int d,n,yr,leap=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void takeDatas() throws Exception
{
System.out.print("\nDAY NUMBER:");
d=Integer.parseInt(br.readLine());
System.out.print("\nYEAR NUMBER:");
yr=Integer.parseInt(br.readLine());
System.out.print("\nDAY AFTER (N):");
n=Integer.parseInt(br.readLine());
if (d<=1 || d>=366)
{
System.out.print("\nDAY NUMBER OUT OF RANGE");
System.exit (0);
}
if (n<=0 || n>=101)
{
System.out.print("\nDATE AFTER (N DAYS) OUT OF RANGE");
System.exit (0);
}
}
public void isLeap()
{
if(yr%100==0 && yr%400==0)
leap++;
else if(yr%100!=0 && yr%4==0)
leap++;
}
public void show()
{
int i;
n=n+d;
for(i=0;i<=11;i++)
{
d=d-days[i];
if(d< days[i])
break;
}
System.out.print("\nDATE: "+ d);
if(d==1)
System.out.print(" ST ");
else if(d==2)
System.out.print(" ND ");
else if(d==3)
System.out.print(" RD ");
else
System.out.print(" TH ");
System.out.print(mon[i+1] + "," + yr);
/* mon[i+1] as loop terminates when complete number of days of the previous month is taken */
// AFTER 'N' NUMBER OF DAYS
i=0;
for(;;)
{
n=n-days[i++];
if(i==12)
i=0;
if(n< days[i])
break;
}
System.out.print("\nDATE: "+ n);
if(d==1)
System.out.print(" ST ");
else if(d==2)
System.out.print(" ND ");
else if(d==3)
System.out.print(" RD ");
else
System.out.print(" TH ");
System.out.print(mon[i] + "," + yr);
/* Here 'i' was incremented before exit from loop */
}
public static void main(String args[]) throws Exception
{
A ob=new A();
ob.takeDatas();
ob.isLeap();
ob.show();
}
}
import java.io.*;
class A
{
int days[]={31,28,31,30,31,30,31,31,30,31,30,31};
String mon[]={"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"};
int d,n,yr,leap=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void takeDatas() throws Exception
{
System.out.print("\nDAY NUMBER:");
d=Integer.parseInt(br.readLine());
System.out.print("\nYEAR NUMBER:");
yr=Integer.parseInt(br.readLine());
System.out.print("\nDAY AFTER (N):");
n=Integer.parseInt(br.readLine());
if (d<=1 || d>=366)
{
System.out.print("\nDAY NUMBER OUT OF RANGE");
System.exit (0);
}
if (n<=0 || n>=101)
{
System.out.print("\nDATE AFTER (N DAYS) OUT OF RANGE");
System.exit (0);
}
}
public void isLeap()
{
if(yr%100==0 && yr%400==0)
leap++;
else if(yr%100!=0 && yr%4==0)
leap++;
}
public void show()
{
int i;
n=n+d;
for(i=0;i<=11;i++)
{
d=d-days[i];
if(d< days[i])
break;
}
System.out.print("\nDATE: "+ d);
if(d==1)
System.out.print(" ST ");
else if(d==2)
System.out.print(" ND ");
else if(d==3)
System.out.print(" RD ");
else
System.out.print(" TH ");
System.out.print(mon[i+1] + "," + yr);
/* mon[i+1] as loop terminates when complete number of days of the previous month is taken */
// AFTER 'N' NUMBER OF DAYS
i=0;
for(;;)
{
n=n-days[i++];
if(i==12)
i=0;
if(n< days[i])
break;
}
System.out.print("\nDATE: "+ n);
if(d==1)
System.out.print(" ST ");
else if(d==2)
System.out.print(" ND ");
else if(d==3)
System.out.print(" RD ");
else
System.out.print(" TH ");
System.out.print(mon[i] + "," + yr);
/* Here 'i' was incremented before exit from loop */
}
public static void main(String args[]) throws Exception
{
A ob=new A();
ob.takeDatas();
ob.isLeap();
ob.show();
}
}
No comments:
Post a Comment