Created
December 28, 2016 12:42
-
-
Save mokomokohitsuzi/145d03c3ea554d66fcd15a64c5c0c713 to your computer and use it in GitHub Desktop.
新・明解Java入門 演習7-6
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
import java.util.Scanner; | |
public class En07_06 { | |
public static void main(String[] args) { | |
Scanner stdIn = new Scanner(System.in); | |
System.out.println("季節を表示します。"); | |
System.out.print("月を入力して下さい。:"); | |
int m = stdIn.nextInt(); | |
printSeason(m); | |
} | |
// switch文で表示を変更する。 | |
static void printSeason(int m) { | |
switch (m) { | |
case 12: | |
case 1: | |
case 2: | |
System.out.print("冬"); | |
break; | |
case 3: | |
case 4: | |
case 5: | |
System.out.print("春"); | |
break; | |
case 6: | |
case 7: | |
case 8: | |
System.out.print("夏"); | |
break; | |
case 9: | |
case 10: | |
case 11: | |
System.out.print("秋"); | |
break; | |
default: | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment