Write a program to input a complete date with its day and the output will show the day of the first day of the year of the input year.
Example: 21-4-2018
Saturday
Output: Monday
Saturday
Output: Monday
import java.io.*;
public class YearDay {
public static void main(String[] args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the date: ");
int dt=Integer.parseInt(br.readLine());
System.out.print("Enter the month: ");
int mn=Integer.parseInt(br.readLine());
System.out.print("Enter the year: ");
int yr=Integer.parseInt(br.readLine());
System.out.print("Enter the day: ");
String day=br.readLine();
int arr[]= {31,28,31,30,31,30,31,31,31,30,31,30};
String arrM[]= {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
if(yr%4==0)
arr[1]=29;
int ct=0;
for(int a=0;a<mn-1;a++)
ct+=arr[a];
ct=ct+dt;
int index=0;
for(int a=0;a<7;a++)
{
if(day.equalsIgnoreCase(arrM[a]))
index=a;
}
index+=1;
for(int a=ct;a>=0;a--)
{
index=index-1;
if(index<0)
index=6;
}
if(index==6)
index=0;
else if(yr%4==0)
index=index+1;
System.out.println(arrM[index]);
}
}
Comments
Post a Comment