Calendar or Day predictor

  • This calendar start from 1 January 2000 .

  • PROGRAM :
import java.util.Scanner;
public class Calendar {
 
    public static void main(String[] args) {
     
        int x,y,z,d=0,a,i,count=0,d1=0,d2=0,d3=0,d4=0,d5=0,d6=0;
       
        int d7=0,d8=0,d9=0,d10=0,d11=0,d12=0,d13=0;        System.out.println("Enter the date in the form of DD");
        Scanner s=new Scanner (System.in);
        x= s.nextInt();
        System.out.println("Enter the month in the form of MM");
        y=s.nextInt();
        System.out.println("Enter the year in the form of YYYY");
        z=s.nextInt();
        a=z%100;
       
        for(i=2000;i<=z;i++)
        {
        if(i/4==0)
        {
        count=count+1;
        }
       
        }
       
     
        if(y==1){
         d=(a)*365 + count + x; d1=31;
         }
            if (y==2)
        {
         d=(a)*365 + count + d1+x;d2=31+28;
        }
        if(y==3){
          d=(a)*365 + count + d2+x; d3=31*2+28;
        }
        if(y==4 ){
        d=(a)*365 + count + d3+x; d4=31*2+28+30;
        }
            if (y==5)
        {
        d=(a)*365 + count + d4+x;d5=31*3+28+30;
        }
        if(y==6) {
        d=(a)*365 + count + d5+x;d6=31*3+28+30*2;
        }
        if(y==7 ){
        d=(a)*365 + count + d6+x; d7=31*4+28+30*2;
        }
            if (y==8)
        {
        d=(a)*365 + count + d7+x; d8=31*5+28+30*2;
        }
        if(y==9) {
        d=(a)*365 + count + d8+x; d9=31*5+28+30*3;
        }
        if(y==10){
        d=(a)*365 + count + d9+x; d10=31*6+28+30*3;
        }
            if (y==11)
        {
        d=(a)*365 + count + d10+x; d11=31*6+28+30*4;
        }
        if(y==12) {
        d=(a)*365 + count + d11+x;
        }
       
       
     
         if(z/4==0)
         {
          d=d+1;
         }
         d13=(d+1)%7;
         System.out.println("the day was:");
         if(d13==1){System.out.println("Saturday");}
          if(d13==2){System.out.println("Sunday");}
           if(d13==3){System.out.println("Monday");}
            if(d13==4){System.out.println("Tuesday");}
             if(d13==5){System.out.println("Wednesday");}
              if(d13==6){System.out.println("Thursday");}
               if(d13==0){System.out.println("Friday");}
   
    }
}

  • OUTPUT :
Enter the date in the form of DD
23
Enter the month in the form of MM
03
Enter the year in the form of YYYY
2017
the day was:

thursday

No comments:

Post a Comment