-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDate.java
More file actions
84 lines (83 loc) · 1.23 KB
/
Date.java
File metadata and controls
84 lines (83 loc) · 1.23 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
75
76
77
78
79
80
81
82
83
84
import java.util.Scanner;
class Date
{
int day,month,year;
Date(int day,int month,int year)
{
this.day=day;
this.month=month;
this.year=year;
}
public boolean CheckValid()
{
boolean leap_year;
if(year%4==0)
leap_year=true;
else
leap_year=false;
if(day<=31 && month<=12 && year>=0)
{
if(month==2 && leap_year)
{
if(day<=29)
{
return true;
}
else
{
return false;
}
}
else if(month==2 && !leap_year)
{
if(day<=28)
{
return true;
}
else
{
return false;
}
}
else if(month%2==0)
{
if(day<=30)
{
return true;
}
else
{
return false;
}
}
else
{
if(day<=31)
{
return true;
}
else
{
return false;
}
}
}
else
return false;
}
public static void main(String[] args)
{
Scanner read=new Scanner(System.in);
System.out.println("Enter the day:");
int day=read.nextInt();
System.out.println("Enter the month:");
int month=read.nextInt();
System.out.println("Enter the year:");
int year=read.nextInt();
Date inst1=new Date(day,month,year);
if(inst1.CheckValid())
System.out.println("Valid date");
else
System.out.println("Invalid date");
}
}