Created
October 23, 2016 12:11
-
-
Save mokomokohitsuzi/c066887953af392f1e41d6f3d990e7dd to your computer and use it in GitHub Desktop.
新・明解Java入門 演習3-17
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.Random; | |
public class En3_17 { | |
public static void main(String[] args) { | |
Random rand = new Random(); | |
// ランダムで0~2までの乱数を生成。 | |
int janken = rand.nextInt(3); | |
switch (janken) { | |
case 0: | |
System.out.println("グー"); | |
break; // 値が0の場合はグー。 | |
case 1: | |
System.out.println("チョキ"); | |
break; // 値が1の場合はチョキ。 | |
case 2: | |
System.out.println("パー"); | |
break; // 値が3の場合はパー。 | |
default: | |
System.out.println("存在しません。"); | |
break; // 念のためデフォルトも用意。 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment