Created
June 12, 2012 12:42
-
-
Save editnuki/2917281 to your computer and use it in GitHub Desktop.
標準入力から月を入力するとその季節が表示されるプログラム。0を入力して終了する。
This file contains hidden or 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
import java.io.*; | |
public class Season { | |
public static void main(String[] args) { | |
BufferedReader reader = new BufferedReader(new InputStreamReader( | |
System.in)); | |
String winter = "冬"; | |
String spring = "春"; | |
String summer = "夏"; | |
String aki = "秋"; | |
boolean flag = true; | |
while (flag) { | |
try { | |
System.out.println("1~12の整数値を入力してください"); | |
String line = reader.readLine(); | |
int month = Integer.parseInt(line); | |
switch (month) { | |
case 12: | |
case 1: | |
case 2: | |
System.out.println(winter); | |
break; | |
case 3: | |
case 4: | |
case 5: | |
System.out.println(spring); | |
break; | |
case 6: | |
case 7: | |
case 8: | |
System.out.println(summer); | |
break; | |
case 9: | |
case 10: | |
case 11: | |
System.out.println(aki); | |
break; | |
case 0: | |
System.out.println("終了"); | |
flag = false; | |
break; | |
default: | |
System.out.println("?"); | |
} | |
} catch (NumberFormatException e) { | |
System.out.println("整数だけ入力してください"); | |
} catch (IOException e) { | |
System.out.println("不明なエラー"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
■20120612_2150
defaultの際にbreakがなかったので追記