-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDOB.java
More file actions
74 lines (72 loc) · 1.62 KB
/
Copy pathDOB.java
File metadata and controls
74 lines (72 loc) · 1.62 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.util.*;
public class DOB
{
int d,m,y,day;
DOB()
{
day=d=m=y=0;
}
void input()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter your date of birth");
d=sc.nextInt();
m=sc.nextInt();
y=sc.nextInt();
if(y>2019)
{
System.out.println("INVALID");
System.exit(0);
}
}
void process()
{
int a[]={31,29,31,30,31,30,31,31,30,31,30,31};
int b[]={31,28,31,30,31,30,31,31,30,31,30,31};
if(y%400==0||y%4==0)
{
if(m==2&&d>29)
{
System.out.println("INVALID");
System.exit(0);
}
else if((m==4||m==6||m==9||m==11)&&d>30)
{
System.out.println("INVALID");
System.exit(0);
}
else
{
for(int i=0;i<m-1;i++)
day+=a[i];
day+=d-1;
}
}
else
{
if(m==2&&d>28)
{
System.out.println("INVALID");
System.exit(0);
}
else if((m==4||m==6||m==9||m==11)&&d>30)
{
System.out.println("INVALID");
System.exit(0);
}
else
{
for(int i=0;i<m-1;i++)
day+=b[i];
day+=d-1;
}
}
System.out.println("VALID DATE\n"+day);
}
static void main()
{
DOB ob=new DOB();
ob.input();
ob.process();
}
}