Date Calculation

Enter the number of days elapsed
233
Enter year
2008
Enter the number of days elapsed after the previous date
17
OUTPUT:
20, August 2008
6, September 2008
import java.io.*;
class Date_Calculation
 {
     public static void main() throws IOException
      {
          InputStreamReader x = new InputStreamReader(System.in);
          BufferedReader y = new BufferedReader(x);
          System.out.println(“Enter the number of days elapsed”);
          int dt = Integer.parseInt(y.readLine());
          System.out.println(“Enter year”);
          int yr = Integer.parseInt(y.readLine());
          System.out.println(“Enter the number of days elapsed after the previous date”);
          int n = Integer.parseInt(y.readLine());
          calculate_date(dt,yr);
          dt=dt+n;
          if(dt>366)
          {
              dt=dt-365;
              yr++;
          }
          calculate_date(dt,yr);
        }
     public static void calculate_date(int dt, int yr)
          {
              int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
              String mnt[] = {“”,”January”,”February”,”March”,”April”,”May”,”June”,”July”,”August”,”September”,”October”,”November”,”December”};
              if(yr%4==0)
              month[2]=29;
              int m=0,sum=0;
              for(m=1;m<=12;m++)
              {
                sum = sum + month[m];
                if(sum>=dt)
                break;
              }
              System.out.println(month[m]-(sum-dt)+”, “+mnt[m]+” “+yr);
        }
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s