Ad

This code will take an input in (dd mm yyyy) format and check whether it is a valid date or not. Then it will display the day value and the name of the day of the week of that date.

SAMPLE INPUT:
Enter the Date:(DD MM YYYY): 31 12 2018

SAMPLE OUTPUT:
The day value is: 365 days and the day is Monday

import java.io.*;
class Date
{

public static void main()throws IOException
{

BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

System.out.print("Enter the Date:(DD MM YYYY): ");
String k=in.readLine();

int d=Integer.parseInt(k.substring(0,2)), c,m=Integer.parseInt(k.substring(3,5)), y=Integer.parseInt(k.substring(6)), i, a1[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
String a2[]={"Sunday","Monday","Tuesday","Tuesday","Wednesday","Thursday","Friday","Saturday"};

if((y%4==0 && y%100!=0)||y%400==0)
a1[2]=29;

if(m<1 || m>12 || d<1 || d>a1[m])
System.out.println("Invalid Date..............");
else
{
System.out.println("Valid Date.............");

for(i=1;i<m;i++)
d+=a1[i];

c=d;

for(i=1;i<y;i++)
if((i%4==0 && i%100!=0)||i%400==0)
d+=366;
else
d+=365;

System.out.println("The day value is: "+c+" days and thr day is "+a2[d%7]);
}
}
}