Skip to content

Instantly share code, notes, and snippets.

@mokomokohitsuzi
Last active October 23, 2016 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mokomokohitsuzi/11f958d74eb3bfc105026717e0283460 to your computer and use it in GitHub Desktop.
Save mokomokohitsuzi/11f958d74eb3bfc105026717e0283460 to your computer and use it in GitHub Desktop.
新・明解Java入門 演習3-18
import java.util.Scanner;
public class En3_18 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
System.out.print("月を整数値で入力してください(1~12):");
int month = stdIn.nextInt();
//1~12までの入力で季節を分ける。
//break;が無いswitch文は次の行に処理が移る。
switch (month) {
case 12:
case 1:
case 2:
System.out.println("冬です。"); //12~2月は冬
break;
case 3:
case 4:
case 5:
System.out.println("春です。");//3~5月は春
break;
case 6:
case 7:
case 8:
System.out.println("夏です。"); //6~8月は夏
break;
case 9:
case 10:
case 11:
System.out.println("秋です。");//9~11月は秋
break;
default:
//1~12以外の場合は正しい入力を促す。
System.out.println("1~12を入力してください。");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment