-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDate_Valid.java
More file actions
58 lines (58 loc) · 1.97 KB
/
Copy pathDate_Valid.java
File metadata and controls
58 lines (58 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.util.Scanner;
class Date_Valid
{
public static void main(String args[])
{
String date="",r="";
int len=0,a1=0,b1=0,c=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter a date in format dd/mm/yyyy");
date=sc.next();
int a[]={31,28,31,30,31,30,31,31,30,31,30,31};
String b[]={"January","February","March","April","May","June","July","August","September","October","November","December"};
len=date.length();
if(len==10)
{
a1=Integer.parseInt(date.substring(0,2));
b1=Integer.parseInt(date.substring(3,5));
c=Integer.parseInt(date.substring(6));
if(c%100==0&&c%4==0||c%400==0||c%4==0)
{
if(b1!=02)
{
if(a1>0||a1<32||b1>0||b1<12)
{
if(a1==1||a1==31)
r=a1+"st";
else if(a1==2)
r=a1+"nd";
else if(a1==3)
r=a1+"rd";
else
r=a1+"th";
System.out.println("date valid"+"\n"+r+" "+b[b1-1]+" "+c);
}
else
System.out.println("the date is invalid!");
}
else if(a1<0||a1>32||b1<0||b1>12)
System.out.println("the date is invalid!");
else if(b1==02)
{
a[1]=29;
if(a1==1||a1==31)
r=a1+"st";
else if(a1==2)
r=a1+"nd";
else if(a1==3)
r=a1+"rd";
else
r=a1+"th";
System.out.println("date valid"+"\n"+r+" "+b[b1-1]+" "+c);
}
}
else
System.out.println("The date is invalid!");
}
}
}