import java.text.ParseException;
import java.time.LocalDate;
import java.util.Scanner;
public class P2 {
public static void main(String[] args) throws ParseException {
LocalDate date = LocalDate.now();
Scanner scanner = new Scanner(System.in);
String s = scanner.nextLine();
int year = Integer.parseInt(s.substring(0, 4));
int month = Integer.parseInt(s.substring(4, 6));
int day = Integer.parseInt(s.substring(6, 8));
date = date.withYear(year);
date = date.withMonth(month);
date = date.withDayOfMonth(day);
date = date.plusDays(1);
String c = null;
String d = null;
Boolean j = false;
while (true){
String s1 = date.toString().replace("-", "");
if(a(s1)){
if(!j){
c = s1;
j=ture;//已经找到第一个了,把j赋值为ture,停止找下一个
}
if(b(s1)){
d = s1;
break;
}
}
date = date.plusDays(1);
}
System.out.println(c);
System.out.println(d);
}
static boolean a(String str){
for (int i = 0; i < str.length()/2; i++) {
if(str.charAt(i) != str.charAt(str.length()-1-i)){
return false;
}
}
return true;
}
static boolean b(String str){
char[] chars = str.toCharArray();
return chars[0] == chars[2] && chars[2] == chars[5] && chars[5] == chars[7] && chars[1] == chars[3] && chars[3] == chars[4] && chars[4] == chars[6];
}
}
蓝桥杯,java回文日期
最新推荐文章于 2025-06-04 17:43:56 发布