/
ProximosDiasCapicuas.java
52 lines (35 loc) · 1.14 KB
/
ProximosDiasCapicuas.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
package com.lineadecodigo.java.basico;
/**
* @file ProximosDiasCapicuas.java
* @version 1.0
* @author Víctor Cuervo (http://lineadecodigo.com)
* @date 02/febrero/2020
* @url http://lineadecodigo.com/java/xxx/
* @description Cálculo de los próximos días capicuas de los siguientes 1000 años.
*/
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ProximosDiasCapicuas {
public static boolean isValidDate(String strDate){
SimpleDateFormat sdfrmt = new SimpleDateFormat("dd/MM/yyyy");
sdfrmt.setLenient(false);
try {
Date javaDate = sdfrmt.parse(strDate);
} catch (ParseException e) {
return false;
}
return true;
}
public static void main(String[] args) {
for (int year=2020;year<3002;year++) {
StringBuilder sb = new StringBuilder(Integer.toString(year));
String reverseYear = sb.reverse().toString();
String day = reverseYear.substring(0,2);
String month = reverseYear.substring(2,4);
String strDate = day + "/" + month + "/" + year;
if (isValidDate(strDate))
System.out.println(strDate);
}
}
}