-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDayWeek.java
More file actions
30 lines (26 loc) · 840 Bytes
/
DayWeek.java
File metadata and controls
30 lines (26 loc) · 840 Bytes
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
/*
1.2 Built-in types of Data
1.2.29 Day of theweek.
Write a program that takes a date as input
and prints the day of the week that date
falls on.
Your program should take three command line
parameters: m(month), d (day), and y (year).
For m, use 1 for January, 2 for February,
and so forth. For output, print 0 for
Sunday, 1 for Monday, 2 for Tuesday,
and so forth. Use the following formulas,
for the Gregorian calendar:
*/
public class DayWeek {
public static void main(String[] args) {
int m = Integer.parseInt(args[0]);
int d = Integer.parseInt(args[1]);
int y = Integer.parseInt(args[2]);
int y0 = y - (14-m)/12;
int x = y0 + y0/4 - y0/100 + y0/400;
int m0 = m + 12 * ((14-m)/12) -2;
int d0 = (d + x + (31*m0)/12)%7;
System.out.println(d0);
}
}