NY Regents Exam   Teasers   IQ Tests   Chemistry   Biology   GK   C++   Recipes   Search <  a href="/cgi/members/home.cgi" class="toplink">Members   Sign off

## Discussion topic: Contributed Answer/Explanation to Q. 3

#### Viewing messages

{
public void main(int dn,int y,int N)
{
String s[]={"st","nd","rd","th"};
String b[]={"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPT EMBER","OCTOBER","NOVEMBER","DECEMBER"};
while(dn!=0)
{
if(y%4==0)
{
int a[]={31,29,31,30,31,30,31,31,30,31,30,31};
int s1=31,i=1,d;
String p="";
while(s1 {
s1=s1+a[i];
++i;
}
s1=s1-a[i-1];
d=dn-s1;
int m=i-1;
if(d==1||d==21||d==31)
p=s[0];
else if(d==2||d==22)
p=s[1];
else if(d==3)
p=s[2];
else
p=s[3];
System.out.println(+d+p+" "+b[m]+" "+y);
int n=dn+N;
if(n>366)
{
n=n-366;
y++;
}
s1=31;
i=1;
d=0;
String k="";
while(s1 {
s1=s1+a[i];
++i;
}
s1=s1-a[i-1];
d=n-s1;
m=i-1;
if(d==1||d==21||d==31)
k=s[0];
else if(d==2||d==22)
k=s[1];
else if(d==3)
k=s[2];
else
k=s[3];
if(m>11)
k=s[4];
System.out.println("DATE AFTER "+N+" DAYS IS "+d+k+" "+b[m]+" "+y);
}
else
if(y%4!=0)
{
int a[]={31,29,31,30,31,30,31,31,30,31,30,31};
int s1=31,i=1,d;
String p="";
while(s1 {
s1=s1+a[i];
++i;
}
s1=s1-a[i-1];
d=dn-s1;
int m=i-1;
if(d==1||d==21||d==31)
p=s[0];
else if(d==2||d==22)
p=s[1];
else if(d==3)
p=s[2];
else
p=s[3];
System.out.println(+d+p+" "+b[m]+" "+y);
int n=dn+N;
if(n>365)
{
n=n-365;
y++;
}
s1=31;
i=1;
d=0;
String k="";
while(s1 {
s1=s1+a[i];
++i;
}
s1=s1-a[i-1];
d=n-s1-1;
m=i-1;
if(d==1||d==21||d==31)
k=s[0];
else if(d==2||d==22)
k=s[1];
else if(d==3)
k=s[2];
else
k=s[3];
if(m>11)
k=s[4];
System.out.println("DATE AFTER "+N+" DAYS IS "+(d+1)+k+" "+b[m]+" "+y);
}
break;
}
System.out.println("Invalid date.Try Again");
}
}

To post to this forum, you must be signed in as a Syvum member. Please sign in / register as a member.