-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFun54.java
More file actions
90 lines (76 loc) · 2.37 KB
/
Fun54.java
File metadata and controls
90 lines (76 loc) · 2.37 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
85
86
87
88
89
90
package fun;
public class Fun54 {
public static void main(String[] args) {
PrevDate(1, 1, 2001);//
PrevDate(1, 3, 2000);
PrevDate(1, 3, 2001);
PrevDate(15, 5, 2001);
PrevDate(1, 3, 2020);
PrevDate(29, 2, 2019);
// PrevDate(29,);
}
public static void PrevDate(int d, int m, int y) {
if (m == 1 && d == 1) {
y--;
m = 12;
System.out.print(y + ".");
System.out.print(MonthDay(y, m)+".");
System.out.print(m + "\n");
} else if (d == 29 && m == 2) {
if (MonthDay(y, m) == 29) {
d--;
System.out.print(y + ".");//2000
System.out.print(m + ".");
System.out.print(d + "\n");//1.
} else if (MonthDay(y, m) == 28) {
System.out.println("Bunday kun yo`q");
}
}else if (d == 1) {
m--;
System.out.print(y + ".");//2000
System.out.print(MonthDay(y, m)+".");
System.out.print(m + "\n");
} else if (d > 1 && d < 32) {
d--;
System.out.print(y + ".");//2000
System.out.print(d + ".");
System.out.print(m + "\n");
}
}
public static int MonthDay(int y, int m) {
int b, c, f;
b = y % 100;//1300 = b ==> 00
c = y % 400;//1300-1200= c ==> 100
f = y % 4;
if (b == 0) {
if (c == 0) {
switch (m) {
case 1, 3, 5, 7, 8, 10, 12 -> m = 31;
case 2 -> m = 29;
case 4, 6, 9, 11 -> m = 30;
}
} else {
switch (m) {
case 1, 3, 5, 7, 8, 10, 12 -> m = 31;
case 2 -> m = 28;
case 4, 6, 9, 11 -> m = 30;
}
}
} else {
if (f == 0) {
switch (m) {
case 1, 3, 5, 7, 8, 10, 12 -> m = 31;
case 2 -> m = 29;
case 4, 6, 9, 11 -> m = 30;
}
} else {
switch (m) {
case 1, 3, 5, 7, 8, 10, 12 -> m = 31;
case 2 -> m = 28;
case 4, 6, 9, 11 -> m = 30;
}
}
}
return m;
}
}