日期對稱程序

今天是世界完全對稱日,2011年11月2日(20111102).這個日子將是現今人們所能經歷的最後一個“世界完全對稱日”。這個比百年等一回的光棍節更值得紀念有木有!


網上又在流轉一些特別的節日,有點誇大的意思,無聊用程序驗證一下:

package ob;

public class DateSymmetry {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String[] s1 = new String[100];
		String[] s2 = new String[100];
		char[] temp = null;
		for(int i=0; i<100; i++) {
			s1[i] = (2000 + i) + "";
			temp = s1[i].toCharArray();
			String month = "" + temp[temp.length-1] + temp[temp.length-2];
			String day = "" + temp[temp.length-3] + temp[temp.length-4];
			int m = Integer.parseInt(month);
			int d = Integer.parseInt(day);
			if(m > 0 && m < 13 && d > 0 && d < 31) {
				String str = month + day;
				s2[i] = s1[i] + str;
			}
		}
		for (String str : s2) {
			if(str != null) {
				System.out.println(str);
			}
		}
	}
}

輸出結果:

20011002
20100102
20111102
20200202
20211202
20300302
20400402
20500502
20600602
20700702
20800802
20900902



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章