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

 Page 1 of 1 From: sasmadhj Reply 1 of 19 Reply Subject: Contributed Answer/Explanation to Q. 3 ``` read a single staterment .arrange the words in ascending order write a program in java ```Posted at: Mon Feb 1 14:03:39 2010 (GMT) From: sandeep1445 Reply 2 of 19 Reply Subject: Contributed Answer/Explanation to Q. 2 ``` programme code in java ```Posted at: Thu Feb 4 13:54:13 2010 (GMT) From: mistressofmischief Reply 3 of 19 Reply Subject: Contributed Answer/Explanation to Q. 1 ``` class date
{
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");
}
}

```Posted at: Sun Feb 21 15:19:48 2010 (GMT) From: prashiss Reply 4 of 19 Reply Subject: Contributed Answer/Explanation to Q. 2 ``` follow the instructions given along with the coding given below. import java.io.*; class matrix { public static void main()throws IOException { int m,n,i,j; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the values of m and n:"); m=Integer.parseInt(br.readLine()); n=Integer.parseInt(br.readLine()); int M[][]=new int[m][n]; System.out.println("Enter the elements to be entered into the matrix:"); for(i=0;ie[j+1]) { t=e[j]; e[j]=e[j+1]; e[j+1]=t; } } } int sum=0; for(i=0;i=0;j--) { M[i][j]=e[k]; k++; } j=0; for(i=m-2;i>0;i--) { M[i][j]=e[k]; k++; } System.out.println("Rearranged Matrix:"); for(i=0;i #include using namespace std; bool checkleap(int y); string printdate(int n, int y); bool checkleap(int y) {     return y % 400 == 0 || (y % 4 == 0 && y % 100 != 0); } string printdate(int n, int y) {     int year = y, month=1, days=n;     y = checkleap(y) ? 1 : 0;                  while( n > 0)     {         if(month >= 13)         {             y = checkleap(++year) ? 1 : 0;             month = 1;         }         days = n;         if(month == 2) if(y==1) n -= 29;                        else n -= 28;         else if(month <= 7) if(month % 2 == 1) n -= 31;                             else n -= 30;         else         {             if(month % 2 == 0) n -= 31;             else n -= 30;         }         month++;     }     string months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };     string app = "th";     if( days % 10 == 1) app = "st";     else if(days % 10 == 2) app = "nd";     else if(days % 10 == 3) app = "rd";     stringstream val;     val << days << app << " " << months[month-2] << " " << year;     return val.str(); } int main() {     int n,y,after;     cout << "Enter the number of days, year and additional number of days: ";     cin >> n >> y >> after;     bool err = n < 1 || n > 366;     if(!checkleap(y)) if( n > 365) err = true;     if(err) { cout << "Incorrect input." << endl; return 1; }     cout << "Current Date: \t" << printdate(n,y) << endl << "Date after " << after << " days: " << printdate(n+after,y) << endl;     return 0; } ```Posted at: Tue Jan 17 20:04:33 2012 (GMT) From: rushilpaul Reply 6 of 19 Reply View replies (2) Subject: Contributed Answer/Explanation to Q. 3 ``` Look at the code and follow the algorithm written after it  #include #include using namespace std; bool checkleap(int y); string printdate(int n, int y); bool checkleap(int y) {     return y % 400 == 0 || (y % 4 == 0 && y % 100 != 0); } string printdate(int n, int y) {     int year = y, month=1, days=n;     y = checkleap(y) ? 1 : 0;                  while( n > 0)     {         if(month > 12)         {             y = checkleap(++year) ? 1 : 0;             month = 1;         }         days = n;         if(month == 2) if(y==1) n -= 29;                        else n -= 28;         else if(month <= 7) if(month % 2 == 1) n -= 31;                             else n -= 30;         else         {             if(month % 2 == 0) n -= 31;             else n -= 30;         }         month++;     }     string months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };     string app = "th";     if( days % 10 == 1) app = "st";     else if(days % 10 == 2) app = "nd";     else if(days % 10 == 3) app = "rd";     stringstream val;     val << days << app << " " << months[month-2] << " " << year;     return val.str(); } int main() {     int n,y,after;     cout << "Enter the number of days, year and additional number of days: ";     cin >> n >> y >> after;     bool err = n < 1 || n > 366;     if(!checkleap(y)) if( n > 365) err = true;     if(err) { cout << "Incorrect input." << endl; return 1; }     cout << "Current Date: \t" << printdate(n,y) << endl << "Date after " << after << " days: " << printdate(n+after,y) << endl;     return 0; }  // end of program   -----------------------------ALGORITHM-------------------------------------- -------- The first seven months of the year have 31 and 30 days alternately with an exception of February. That means for all m <= 7, if m is divisble by 2, then no. of days is 30, else 31. and if m = 2, then check for leap year. This is very simple: (y is divisble by 4 but not by 100) or (y is divisible by 400). Continuing, months from 8 to 12 have 31 and 30 days alternately. Again check if m is divisible by 2. If yes then its 31 else 30. (this time it gets reversed since Jul and Aug, both have 31 days) Keep on subtracting the number of days in each month from variable days (which was the input), and check whether the number of remaining days are <= 0. If yes, then break out of the loop and the last positive value of variable "days" will be the date. (assign another variable the value of n just before changing value of "days") For months, keep a counter which starts from 1. As soon as months reaches a value > 12, assign it 1, increment year, and check for leap year again.   Put all of this in a function and call it twice. The second time, call it giving number of days = earlier no. of days + second inputted no. of days.  printdate( days + after ) ```Posted at: Tue Jan 17 20:35:50 2012 (GMT) From: rushilpaul Reply 7 of 19 Reply Subject: Contributed Answer/Explanation to Q. 3 ``` Look at the code and follow the algorithm written after it #include #include using namespace std; bool checkleap(int y); string printdate(int n, int y); bool checkleap(int y) { return y % 400 == 0 || (y % 4 == 0 && y % 100 != 0); } string printdate(int n, int y) { int year = y, month=1, days=n; y = checkleap(y) ? 1 : 0; while( n > 0) { if(month > 12) { y = checkleap(++year) ? 1 : 0; month = 1; } days = n; if(month == 2) if(y==1) n -= 29; else n -= 28; else if(month <= 7) if(month % 2 == 1) n -= 31; else n -= 30; else { if(month % 2 == 0) n -= 31; else n -= 30; } month++; } string months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; string app = "th"; if( days % 10 == 1) app = "st"; else if(days % 10 == 2) app = "nd"; else if(days % 10 == 3) app = "rd"; stringstream val; val << days << app << " " << months[month-2] << " " << year; return val.str(); } int main() { int n,y,after; cout << "Enter the number of days, year and additional number of days: "; cin >> n >> y >> after; bool err = n < 1 || n > 366; if(!checkleap(y)) if( n > 365) err = true; if(err) { cout << "Incorrect input." << endl; return 1; } cout << "Current Date: \t" << printdate(n,y) << endl << "Date after " << after << " days: " << printdate(n+after,y) << endl; return 0; }  // end of program   -----------------------------ALGORITHM-------------------------------------- -------- The first seven months of the year have 31 and 30 days alternately with an exception of February. That means for all m <= 7, if m is divisble by 2, then no. of days is 30, else 31. and if m = 2, then check for leap year. This is very simple: (y is divisble by 4 but not by 100) or (y is divisible by 400). Continuing, months from 8 to 12 have 31 and 30 days alternately. Again check if m is divisible by 2. If yes then its 31 else 30. (this time it gets reversed since Jul and Aug, both have 31 days) Keep on subtracting the number of days in each month from variable days (which was the input), and check whether the number of remaining days are <= 0. If yes, then break out of the loop and the last positive value of variable "days" will be the date. (assign another variable the value of n just before changing value of "days") For months, keep a counter which starts from 1. As soon as months reaches a value > 12, assign it 1, increment year, and check for leap year again.   Put all of this in a function and call it twice. The second time, call it giving number of days = earlier no. of days + second inputted no. of days. i.e. printdate( days + after ) ```Posted at: Tue Jan 17 20:50:11 2012 (GMT) From: rushilpaul Reply 8 of 19 Reply Subject: Contributed Answer/Explanation to Q. 1 ``` #include #include using namespace std; bool checkleap(int y); string printdate(int n, int y); bool checkleap(int y) { return y % 400 == 0 || (y % 4 == 0 && y % 100 != 0); } string printdate(int n, int y) { int year = y, month=1, days=n; y = checkleap(y) ? 1 : 0; while( n > 0) { if(month > 12) { y = checkleap(++year) ? 1 : 0; month = 1; } days = n; if(month == 2) if(y==1) n -= 29; else n -= 28; else if(month <= 7) if(month % 2 == 1) n -= 31; else n -= 30; else { if(month % 2 == 0) n -= 31; else n -= 30; } month++; } string months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; string app = "th"; if( days % 10 == 1) app = "st"; else if(days % 10 == 2) app = "nd"; else if(days % 10 == 3) app = "rd"; stringstream val; val << days << app << " " << months[month-2] << " " << year; return val.str(); } int main() { int n,y,after; cout << "Enter the number of days, year and additional number of days: "; cin >> n >> y >> after; bool err = n < 1 || n > 366; if(!checkleap(y)) if( n > 365) err = true; if(err) { cout << "Incorrect input." << endl; return 1; } cout << "Current Date: \t" << printdate(n,y) << endl << "Date after " << after << " days: " << printdate(n+after,y) << endl; return 0; }  // end of program   -----------------------------ALGORITHM-------------------------------------- -------- The first seven months of the year have 31 and 30 days alternately with an exception of February. That means for all m <= 7, if m is divisble by 2, then no. of days is 30, else 31. and if m = 2, then check for leap year. This is very simple: (y is divisble by 4 but not by 100) or (y is divisible by 400). Continuing, months from 8 to 12 have 31 and 30 days alternately. Again check if m is divisible by 2. If yes then its 31 else 30. (this time it gets reversed since Jul and Aug, both have 31 days) Keep on subtracting the number of days in each month from variable days (which was the input), and check whether the number of remaining days are <= 0. If yes, then break out of the loop and the last positive value of variable "days" will be the date. (assign another variable the value of n just before changing value of "days") For months, keep a counter which starts from 1. As soon as months reaches a value > 12, assign it 1, increment year, and check for leap year again.   Put all of this in a function and call it twice. The second time, call it giving number of days = earlier no. of days + second inputted no. of days. i.e. printdate( days + after ) ```Posted at: Tue Jan 17 20:52:21 2012 (GMT) From: rushilpaul Reply 9 of 19 Reply Subject: Contributed Answer/Explanation to Q. 1 ``` #include #include using namespace std; bool checkleap(int y); string printdate(int n, int y); bool checkleap(int y) { return y % 400 == 0 || (y % 4 == 0 && y % 100 != 0); } string printdate(int n, int y) { int year = y, month=1, days=n; y = checkleap(y) ? 1 : 0; while( n > 0) { if(month > 12) { y = checkleap(++year) ? 1 : 0; month = 1; } days = n; if(month == 2) if(y==1) n -= 29; else n -= 28; else if(month <= 7) if(month % 2 == 1) n -= 31; else n -= 30; else { if(month % 2 == 0) n -= 31; else n -= 30; } month++; } string months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; string app = "th"; if( days % 10 == 1) app = "st"; else if(days % 10 == 2) app = "nd"; else if(days % 10 == 3) app = "rd"; stringstream val; val << days << app << " " << months[month-2] << " " << year; return val.str(); } int main() { int n,y,after; cout << "Enter the number of days, year and additional number of days: "; cin >> n >> y >> after; bool err = n < 1 || n > 366; if(!checkleap(y)) if( n > 365) err = true; if(err) { cout << "Incorrect input." << endl; return 1; } cout << "Current Date: \t" << printdate(n,y) << endl << "Date after " << after << " days: " << printdate(n+after,y) << endl; return 0; }  // end of program   -----------------------------ALGORITHM-------------------------------------- -------- The first seven months of the year have 31 and 30 days alternately with an exception of February. That means for all m <= 7, if m is divisble by 2, then no. of days is 30, else 31. and if m = 2, then check for leap year. This is very simple: (y is divisble by 4 but not by 100) or (y is divisible by 400). Continuing, months from 8 to 12 have 31 and 30 days alternately. Again check if m is divisible by 2. If yes then its 31 else 30. (this time it gets reversed since Jul and Aug, both have 31 days) Keep on subtracting the number of days in each month from variable days (which was the input), and check whether the number of remaining days are <= 0. If yes, then break out of the loop and the last positive value of variable "days" will be the date. (assign another variable the value of n just before changing value of "days") For months, keep a counter which starts from 1. As soon as months reaches a value > 12, assign it 1, increment year, and check for leap year again.   Put all of this in a function and call it twice. The second time, call it giving number of days = earlier no. of days + second inputted no. of days. i.e. printdate( days + after ) ```Posted at: Tue Jan 17 20:55:23 2012 (GMT) From: rushilpaul Reply 10 of 19 Reply Subject: Contributed Answer/Explanation to Q. 1 ``` #include "iostream" #include "sstream" using namespace std; bool checkleap(int y); string printdate(int n, int y); bool checkleap(int y) { return y % 400 == 0 || (y % 4 == 0 && y % 100 != 0); } string printdate(int n, int y) { int year = y, month=1, days=n; y = checkleap(y) ? 1 : 0; while( n > 0) { if(month > 12) { y = checkleap(++year) ? 1 : 0; month = 1; } days = n; if(month == 2) if(y==1) n -= 29; else n -= 28; else if(month <= 7) if(month % 2 == 1) n -= 31; else n -= 30; else { if(month % 2 == 0) n -= 31; else n -= 30; } month++; } string months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; string app = "th"; if( days % 10 == 1) app = "st"; else if(days % 10 == 2) app = "nd"; else if(days % 10 == 3) app = "rd"; stringstream val; val << days << app << " " << months[month-2] << " " << year; return val.str(); } int main() { int n,y,after; cout << "Enter the number of days, year and additional number of days: "; cin >> n >> y >> after; bool err = n < 1 || n > 366; if(!checkleap(y)) if( n > 365) err = true; if(err) { cout << "Incorrect input." << endl; return 1; } cout << "Current Date: \t" << printdate(n,y) << endl << "Date after " << after << " days: " << printdate(n+after,y) << endl; return 0; }  // end of program   -----------------------------ALGORITHM-------------------------------------- -------- The first seven months of the year have 31 and 30 days alternately with an exception of February. That means for all m <= 7, if m is divisble by 2, then no. of days is 30, else 31. and if m = 2, then check for leap year. This is very simple: (y is divisble by 4 but not by 100) or (y is divisible by 400). Continuing, months from 8 to 12 have 31 and 30 days alternately. Again check if m is divisible by 2. If yes then its 31 else 30. (this time it gets reversed since Jul and Aug, both have 31 days) Keep on subtracting the number of days in each month from variable days (which was the input), and check whether the number of remaining days are <= 0. If yes, then break out of the loop and the last positive value of variable "days" will be the date. (assign another variable the value of n just before changing value of "days") For months, keep a counter which starts from 1. As soon as months reaches a value > 12, assign it 1, increment year, and check for leap year again.   Put all of this in a function and call it twice. The second time, call it giving number of days = earlier no. of days + second inputted no. of days. i.e. printdate( days + after ) ```Posted at: Tue Jan 17 20:56:49 2012 (GMT) From: rushilpaul Reply 11 of 19 Reply Subject: Contributed Answer/Explanation to Q. 3 ``` Look at the code and follow the algorithm written after it #include "iostream" #include "sstream" using namespace std; bool checkleap(int y); string printdate(int n, int y); bool checkleap(int y) { return y % 400 == 0 || (y % 4 == 0 && y % 100 != 0); } string printdate(int n, int y) { int year = y, month=1, days=n; y = checkleap(y) ? 1 : 0; while( n > 0) { if(month > 12) { y = checkleap(++year) ? 1 : 0; month = 1; } days = n; if(month == 2) if(y==1) n -= 29; else n -= 28; else if(month <= 7) if(month % 2 == 1) n -= 31; else n -= 30; else { if(month % 2 == 0) n -= 31; else n -= 30; } month++; } string months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; string app = "th"; if( days % 10 == 1) app = "st"; else if(days % 10 == 2) app = "nd"; else if(days % 10 == 3) app = "rd"; stringstream val; val << days << app << " " << months[month-2] << " " << year; return val.str(); } int main() { int n,y,after; cout << "Enter the number of days, year and additional number of days: "; cin >> n >> y >> after; bool err = n < 1 || n > 366; if(!checkleap(y)) if( n > 365) err = true; if(err) { cout << "Incorrect input." << endl; return 1; } cout << "Current Date: \t" << printdate(n,y) << endl << "Date after " << after << " days: " << printdate(n+after,y) << endl; return 0; }  // end of program   -----------------------------ALGORITHM-------------------------------------- -------- The first seven months of the year have 31 and 30 days alternately with an exception of February. That means for all m <= 7, if m is divisble by 2, then no. of days is 30, else 31. and if m = 2, then check for leap year. This is very simple: (y is divisble by 4 but not by 100) or (y is divisible by 400). Continuing, months from 8 to 12 have 31 and 30 days alternately. Again check if m is divisible by 2. If yes then its 31 else 30. (this time it gets reversed since Jul and Aug, both have 31 days) Keep on subtracting the number of days in each month from variable days (which was the input), and check whether the number of remaining days are <= 0. If yes, then break out of the loop and the last positive value of variable "days" will be the date. (assign another variable the value of n just before changing value of "days") For months, keep a counter which starts from 1. As soon as months reaches a value > 12, assign it 1, increment year, and check for leap year again.   Put all of this in a function and call it twice. The second time, call it giving number of days = earlier no. of days + second inputted no. of days. i.e. printdate( days + after ) ```Posted at: Tue Jan 17 20:58:24 2012 (GMT) From: arnab_java Reply 12 of 19 Reply View replies (1) Subject: Contributed Answer/Explanation to Q. 3 ``` This is the answer to Question-3 (String program). import java.io.*; import java.util.*; class Reverse {     public static void main(String []args)throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         System.out.println("Enter the sentence");int t1,t2,n;         String s=br.readLine(),x="",p="",q="";int k=0;         int l=s.length();         for(int i=0;it2)                 {                     t=a[j];                     a[j]=a[j+1];                     a[j+1]=t;                 }             }         }         p=p+a[0];         int l1=p.length();         for(int i=0;it2)                 {                     t=a[j];                     a[j]=a[j+1];                     a[j+1]=t;                 }             }         }         p=p+a[0];         int l1=p.length();         for(int i=0;it2)                 {                     t=a[j];                     a[j]=a[j+1];                     a[j+1]=t;                 }             }         }         p=p+a[0];         int l1=p.length();         for(int i=0;i3)&&(dn<21))?"th":suffix(dn%10))+&qu ot; "+m[mm]+" "+yy);         mm=0;         if((a+N)>td)         {             a=(a+N)-td;             ++yy;         }         else             a+=N;         while(true)         {             if((a-md[mm])<0)                 break;             a-=md[mm];             ++mm;         }             ++mm;             System.out.println("The date after "+N+" days is : "+a+(((a>3)&&(a<21))?"th":suffix(a%10))+" "+m[mm-1]+" "+yy);     }     static boolean isLeap(int y)     {         if((y%100==0&&y%400==0)||(y%100!=0&&y%4==0))             return true;         return false;     } } ```Posted at: Fri Feb 8 15:52:58 2013 (GMT) From: durgesh98 Reply 16 of 19 Reply Subject: Contributed Answer/Explanation to Q. 1 ``` Answer:     import java.util.*; class days {     public static void main()     {         Scanner sc=new Scanner(System.in);         System.out.println("DAY NUMBER");         int day=sc.nextInt();         System.out.println("YEAR");         int year=sc.nextInt();         System.out.println("DAY AFTER(N)");         int day_after=sc.nextInt();         int sum=0;         int newdate=0;         int p=0;         String t="";         int days=day;         int m[]={31,29,31,30,31,30,31,31,30,31,30,31};                 String years[]={"January","February","March","Ap ril","May","June","July","August&quo t;,"September","October","November","Dece mber"};                 if(year%4==0)                 {                     m[1]=29;                 }                 else                 {                     m[1]=28;                 }                 if((day>=1&&day<=366)&&(year>=1000&&year< ;=9999)&&(day_after>=1&&day_after<=100))                 {                 for(int i=0;i<12;i++)                 {                     if(day>=0&&day<=m[i])                     {                         System.out.println(day+" "+years[i]+"  "+year);                         break;                        }                        else                        {                            day=day-m[i];                            p++;                        }                     }                     System.out.println("DAY AFTER "+day_after+" DAYS");                     days=days+day_after;                     int k=0;                     if(days>=366)                     {                         days=days-366;                         k++;                     }                        for(int i=0;i<12;i++)                 {                     if(days>=0&&days<=m[i])                     {                         if(k!=0)                         System.out.println(days+" "+years[i]+"  "+(year+1));                         else                         System.out.println(days+" "+years[i]+"  "+(year));                         break;                        }                        else                        {                            days=days-m[i];                        }                     }                 } } } ```Posted at: Sun Dec 22 06:32:05 2013 (GMT) From: durgesh98 Reply 17 of 19 Reply Subject: Contributed Answer/Explanation to Q. 2 ``` import java.util.*; class matrix { public static void main() { Scanner sc =new Scanner(System.in); System.out.println("Enter Number of Rows"); int m=sc.nextInt(); System.out.println("Enter Number of Columns"); ```Posted at: Sun Dec 22 06:35:25 2013 (GMT) From: ajma Reply 18 of 19 Reply Subject: Contributed Answer/Explanation to Q. 1 ``` import java.io.*; public class date {public void show()throws IOException {BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));  int flag,leap,i,num,mon1,day1,year1;  int dpm[]={31,28,31,30,31,30,31,31,30,31,30,31};  leap=0;  flag=0; System.out.println("\nInput:");  num=Integer.parseInt(buf.readLine());  year1=num%100; num=num/100; mon1=num%100; num=num/100;  day1=num;  if(year1%100==0&&year1%400==0)  leap=1;  else  if(year1%100!=0&&year1%4==0)  leap=1;  if(mon1==2&&leap==1&&dpm[mon1-1]>28)  flag=1;  else   if(mon1==2&&leap==0&&dpm[mon1-1]>28)   flag=1;   else   if(day1>dpm[mon1-1])   flag=1;   if(flag==1)   {System.out.println("\nInvalid Date...");       return;}     leap=day1%10;     System.out.print("\nOUTPUT:"+day1);     switch(leap)     { case 0:         case 4:         case 5:         case 6:         case 7:         case 8:         case 9:         System.out.print("th ");         break;         case 1:         System.out.print("st ");         break;         case 2:         System.out.print("nd ");         break;         case 3:         System.out.print("rd ");         break;}     switch(mon1)    {case 1:         System.out.print("january,");         break;          case 2:         System.out.print("february,");         break;          case 3:         System.out.print("march,");         break;          case 4:         System.out.print("april,");         break;          case 5:         System.out.print("may,");         break;          case 6:         System.out.print("june,");         break;         case 7:         System.out.print("july,");         break;          case  8:         System.out.print("august,");         break;          case 9:         System.out.print("september,");         break;          case 10:         System.out.print("october,");         break;          case 11:         System.out.print("november,");         break;          case 12:         System.out.print("december,");         break;}     System.out.print(year1);}}          ```Posted at: Mon Feb 17 08:37:44 2014 (GMT) From: cr7 Reply 19 of 19 Reply Subject: Contributed Answer/Explanation to Q. 1 ``` import java.io.*; import java.util.*; class date {  public static void main(String ar[])throws IOException  {   BufferedReader z=new BufferedReader(new InputStreamReader(System.in));   int dd,mm,t,yy,N;   String month="",month1="";   System.out.print("Day number:  ");   dd=Integer.parseInt(z.readLine());   System.out.print("Year:  ");   yy=Integer.parseInt(z.readLine());   System.out.print("Days after(N):  ");   N=Integer.parseInt(z.readLine());   Date d=new Date(); //Using date class utility of JAVA which takes year                                    //as year-1900. Months and days start from 0    d.setDate(dd);   d.setMonth(0);   d.setYear(yy-1900);   mm=d.getMonth(); //The following if and else is just for printing name of month   if(mm==0)   month="January";   else if(mm==1)   month="February";   else if(mm==2)   month="March";   else if(mm==3)   month="April";   else if(mm==4)   month="May";   else if(mm==5)   month="June";   else if(mm==6)   month="July";   else if(mm==7)   month="August";   else if(mm==8)   month="September";   else if(mm==9)   month="October";   else if(mm==10)   month="November";   else if(mm==11)   month="December";   System.out.println(d.getDate()+"th "+month+" "+(d.getYear()+1900));   Date d1=new Date(yy-1900,mm/12,dd+N);   t=d1.getMonth();   if(t>11)   t=t/12; //Again the following if and else is just for printing name of month    if(t==0)   month1="January";   else if(t==1)   month1="February";   else if(t==2)   month1="March";   else if(t==3)   month1="April";   else if(t==4)   month1="May";   else if(t==5)   month1="June";   else if(t==6)   month1="July";   else if(t==7)   month1="August";   else if(t==8)   month1="September";   else if(t==9)   month1="October";   else if(t==10)   month1="November";   else if(t==11)   month1="December";   System.out.println("DATE AFTER "+N+" DAYS:"+d1.getDate()+"th "+month1+" "+(d1.getYear()+1900));  } } ```Posted at: Sun Feb 15 04:49:24 2015 (GMT) Page 1 of 1

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