-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinding_Day_From_Given_Date.java
173 lines (154 loc) · 3.49 KB
/
Finding_Day_From_Given_Date.java
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package placements;
import java.util.*;
public class D_Day {
static String count(int date, int month, int year)
{
String ans="";
int m_value=mcount(month);
int y_value=ycount(year);
int l=0,c=2;
int val = year%100;
int q=val/4;
int sum=val+q+y_value+m_value+date;
int a=sum%7;
if(a==0)
ans="Sunday";
else if(a==1)
ans="Monday";
else if(a==2)
ans="Tuesday";
else if(a==3)
ans="Wednesday";
else if(a==4)
ans="Thursday";
else if(a==5)
ans="Friday";
else
ans="Saturday";
return ans;
}
static int mcount(int month)
{
if(month==1)
return 0;
else if(month==2)
return 3;
else if(month==3)
return 3;
else if(month==4)
return 6;
else if(month==5)
return 1;
else if(month==6)
return 4;
else if(month==7)
return 6;
else if(month==8)
return 2;
else if(month==9)
return 5;
else if(month==10)
return 0;
else if(month==11)
return 3;
else
return 5;
}
static int ycount(int year)
{
if(year>=1600 && year<=1699)
return 6;
else if(year>=1700 && year <=1799)
return 4;
else if(year>=1800 && year <=1899)
return 2;
else if(year>=1900 && year <=1999)
return 0;
else
return 6;
}
public static void main(String [] args)
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter the Date in DD/MM/YYYY format");
String dt=sc.next();
// checking the input is correct or not
if(dt.indexOf("/")==2 && dt.lastIndexOf("/")==5)
{
String [] ar = dt.split("/");
int date =Integer.parseInt(ar[0]);
int month = Integer.parseInt(ar[1]);
int year = Integer.parseInt(ar[2]);
//checking date is invalid or not
if(date>31)
{
System.out.println("Invalid Input!");
try {
Thread.sleep(1200);
} catch (Exception e) {}
System.out.println("Program Terminated.");
System.exit(0);
}
//checking month is invalid or not
if(month>12)
{
System.out.println("Invalid Input!");
try {
Thread.sleep(1200);
} catch (Exception e) {}
System.out.println("Program Terminated.");
System.exit(0);
}
//valid case
else
{
if(date>29)
{
if(date==31 && (month==1||month==3||month==5||month==7||month==8||month==10||month==12))
{
System.out.println(count(date,month,year));
}
else if(date==30 && (month==4||month==6||month==9||month==11))
{
System.out.println(count(date,month,year));
}
else
{
System.out.println("Invalid Input!");
try {
Thread.sleep(1200);
} catch (Exception e) {}
System.out.println("Program Terminated.");
System.exit(0);
}
}
else if((date == 29 && month ==2)||date==28||month==2)
{
System.out.println(count(date,month,year));
}
else if(date<=29)
{
System.out.println(count(date,month,year));
}
else
{
System.out.println("Invalid Input!");
try {
Thread.sleep(1200);
} catch (Exception e) {}
System.out.println("Program Terminated.");
System.exit(0);
}
}
}
else
{
System.out.println("Invalid Input!");
try {
Thread.sleep(1200);
} catch (Exception e) {}
System.out.println("Program Terminated.");
System.exit(0);
}
}
}