FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Hackerrank-JavaScript-Solutions/prime-date.java at master · prabaprakash/Hackerrank-JavaScript-Solutions · GitHub
prabaprakash
/
Hackerrank-JavaScript-Solutions
Public
Notifications
You must be signed in to change notification settings
Fork
65
Star
133
Code
Issues
7
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Hackerrank-JavaScript-Solutions
/
prime-date.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
85 lines (72 loc) · 2.12 KB
Breadcrumbs
Hackerrank-JavaScript-Solutions
/
prime-date.java
Copy path
File metadata and controls
85 lines (72 loc) · 2.12 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
java
.
util
.*;
import
java
.
lang
.*;
import
java
.
io
.*;
import
java
.
math
.*;
public
class
Main
{
public
static
int
month
[];
public
static
void
main
(
String
[]
args
)
throws
java
.
lang
.
Exception
{
Scanner
in
=
new
Scanner
(
System
.
in
);
month
=
new
int
[
15
];
String
s
=
in
.
nextLine
();
StringTokenizer
str
=
new
StringTokenizer
(
s
,
"- "
);
int
d1
=
Integer
.
parseInt
(
str
.
nextToken
());
int
m1
=
Integer
.
parseInt
(
str
.
nextToken
());
int
y1
=
Integer
.
parseInt
(
str
.
nextToken
());
int
d2
=
Integer
.
parseInt
(
str
.
nextToken
());
int
m2
=
Integer
.
parseInt
(
str
.
nextToken
());
int
y2
=
Integer
.
parseInt
(
str
.
nextToken
());
int
result
=
findPrimeDates
(
d1
,
m1
,
y1
,
d2
,
m2
,
y2
);
System
.
out
.
println
(
result
);
}
public
static
void
updateLeapYear
(
int
year
) {
if
(
year
%
400
==
0
) {
month
[
2
] =
29
;
}
else
if
(
year
%
100
==
0
) {
month
[
2
] =
28
;
}
else
if
(
year
%
4
==
0
) {
month
[
2
] =
29
;
}
else
{
month
[
2
] =
28
;
}
}
public
static
void
storeMonth
() {
month
[
1
] =
31
;
month
[
2
] =
28
;
month
[
3
] =
31
;
month
[
4
] =
30
;
month
[
5
] =
31
;
month
[
6
] =
30
;
month
[
7
] =
31
;
month
[
8
] =
31
;
month
[
9
] =
30
;
month
[
10
] =
31
;
month
[
11
] =
30
;
month
[
12
] =
31
;
}
public
static
int
findPrimeDates
(
int
d1
,
int
m1
,
int
y1
,
int
d2
,
int
m2
,
int
y2
) {
storeMonth
();
int
result
=
0
;
while
(
true
) {
int
x
=
d1
;
x
=
x
*
100
+
m1
;
x
=
x
*
10000
+
y1
;
if
(
x
%
4
==
0
||
x
%
7
==
0
) {
result
=
result
+
1
;
}
if
(
d1
==
d2
&&
m1
==
m2
&&
y1
==
y2
) {
break
;
}
updateLeapYear
(
y1
);
d1
=
d1
+
1
;
if
(
d1
>
month
[
m1
]) {
m1
=
m1
+
1
;
d1
=
1
;
if
(
m1
>
12
) {
y1
=
y1
+
1
;
m1
=
1
;
}
}
}
return
result
;
}
}
Back
|
FazBrowse Home
|
New Git URL