import java.io.*; class ex5_5 { public static void main(String[] args) throws Exception { BufferedReader inp = new BufferedReader(new InputStreamReader(System.in)); String keybd; // キーボードからの読込用変数 int start, end; // 開始年(start)と終了年(end)用の変数 int i; // 添え字用の変数 System.out.println("===★☆★ 閏年を列挙するプログラムです ★☆★===\n"); System.out.print(" 開始年を西暦で入力してください -->"); keybd = inp.readLine(); start = Integer.parseInt(keybd); // 開始年(start)の値取得 System.out.print(" 終了年を西暦で入力してください -->"); keybd = inp.readLine(); end = Integer.parseInt(keybd); // 終了年(end)の値取得 System.out.println("指定された年の間のうるう年を列挙します "); for (i = start; i <= end; i++) { // 開始年(start)から終了年(end)まで処理を繰り返し if (i % 4 != 0) // (i % 4 > 0) でも可 System.out.print(""); // うるう年ではないので何も表示しない else if (i % 100 != 0) // (i % 100 > 0) でも可 System.out.print(i + "年, "); // うるう年なので表示 else if (i % 400 == 0) System.out.print(i + "年, "); // うるう年なので表示 } } }