# 菜鸟求助：怎样利用Java判断世界完全对称日

0

RT:我想实现一个功能，给定起始年份和终止，判断他们之间的年份是否是世界完全对称日，如果是，则打印出来；

String start = "2010-01-02";
String end = "3000-01-01";

String s = start.replaceAll("-", "");
String[] str={s.substring(0, 4),s.substring(4)};
StringBuffer sb = new StringBuffer(str[1]);
System.out.println(str[0].toString().equals(sb.reverse().toString()));

RainWu | 初学一级 | 园豆：162

1
` 1 package bing.test; 2  3 import java.text.ParseException; 4 import java.text.SimpleDateFormat; 5 import java.util.Date; 6  7 public class SymmetryDay { 8      9     public static void main (String[] args){10         11         String start = "2010-01-01";12         String end = "3000-01-01";13         SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");14         Date startDate;15         long startDateL;16         long endDateL;17         long oneDay = 24*60*60*1000;18         try {19             startDate = myFormatter.parse(start);20             startDateL = startDate.getTime();21             endDateL = myFormatter.parse(end).getTime();22             while(startDateL < endDateL){23                 String s = myFormatter.format(startDate).replaceAll("-", "");24                 String[] str={s.substring(0, 4),s.substring(4)};25                 StringBuffer sb = new StringBuffer(str[1]);26                 if(str[0].toString().equals(sb.reverse().toString())){27                     log(myFormatter.format(startDate));28                 }29                 startDateL = startDateL + oneDay;30                 startDate.setTime(startDateL);31             }32             33         } catch (ParseException e) {34             // TODO Auto-generated catch block35             e.printStackTrace();36         } 37     }38     public static void log(Object m){39         System.out.println(m);40     }41     42 43 }`

xiqobai | 菜鸟二级 |园豆：260 | 2012-01-19 14:29

2010-01-02
2011-11-02
2020-02-02
2021-12-02
2030-03-02
2040-04-02
2050-05-02
2060-06-02
2070-07-02
2080-08-02
2090-09-02
2101-10-12
2110-01-12
2111-11-12
2120-02-12
2121-12-12
2130-03-12
2140-04-12
2150-05-12
2160-06-12
2170-07-12
2180-08-12
2190-09-12
2201-10-22
2210-01-22
2211-11-22
2220-02-22
2221-12-22
2230-03-22
2240-04-22
2250-05-22
2260-06-22
2270-07-22
2280-08-22
2290-09-22

xiqobai | 园豆：260 (菜鸟二级) | 2012-01-19 14:31

RainWu | 园豆：162 (初学一级) | 2012-01-19 14:50

@丿灬钧衡石丶溪:

xiqobai | 园豆：260 (菜鸟二级) | 2012-01-20 09:36

您需要登录以后才能回答，未注册用户请先注册