题目描述
思路分析
暴力+判断
代码实现
package lanqiao;import java.util.Scanner;public class Main {public static String str="";public static boolean isLeap(int year){return (year%4==0&&year%100!=0)||year%400==0;}public static boolean check(int a,int b,int c){//月份效验if(b<1||b>12) return false;if(c<1||c>31) return false;//日效验switch (b){//日期校验case 2:if(isLeap(a)&&c>29) return false;if(!isLeap(a)&&c>28) return false;break;case 4:case 6:case 9:case 11:if(c>30) return false;break;default:break;}if(str.charAt(0)==str.charAt(2)&&str.charAt(2)==str.charAt(5)&&str.charAt(5)==str.charAt(7)&&str.charAt(1)==str.charAt(3)&&str.charAt(3)==str.charAt(4)&&str.charAt(4)==str.charAt(6)){return true;}return false;}public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int cur = scanner.nextInt();int sum=0;for (int i = cur; i <= 89991231; i++) {str="";str+=i;if(check(Integer.parseInt(str.substring(0,4)),Integer.parseInt(str.substring(4,6)),Integer.parseInt(str.substring(6,8)))){sum++;System.out.println(i);if(sum==2){break;}}}}}