Created
September 6, 2012 14:21
-
-
Save anonymous/3656792 to your computer and use it in GitHub Desktop.
和暦の毎年の日数を出力するプログラム
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.mericle; | |
import java.text.DateFormat; | |
import java.text.SimpleDateFormat; | |
import java.util.ArrayList; | |
import java.util.Calendar; | |
import java.util.Locale; | |
public class JapaneseDayCounter { | |
public static void main(String[] args) { | |
ArrayList<String> messages = new ArrayList<String>(); | |
// JRE標準の和暦を使う | |
Locale locale = new Locale("ja", "JP", "JP"); | |
DateFormat format = new SimpleDateFormat("GGGGyy年", locale); | |
Calendar calendar = Calendar.getInstance(locale); | |
for (calendar.set(24, 11, 31) // 平成24年12月31日 | |
; calendar.get(Calendar.ERA) != 0 | |
; calendar.set(Calendar.DAY_OF_YEAR, 1), | |
calendar.add(Calendar.DAY_OF_YEAR, -1)) { | |
messages.add(format.format(calendar.getTime()) | |
+ "は" | |
+ calendar.get(Calendar.DAY_OF_YEAR) | |
+ "日です。"); | |
} | |
// 平成~明治の順を明治~平成に直して出力する | |
for (int i = messages.size() - 1; i >= 0; --i) { | |
System.out.println(messages.get(i)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment