Skip to content

Instantly share code, notes, and snippets.

@mokomokohitsuzi
Created October 23, 2016 12:11
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/c066887953af392f1e41d6f3d990e7dd to your computer and use it in GitHub Desktop.
Save mokomokohitsuzi/c066887953af392f1e41d6f3d990e7dd to your computer and use it in GitHub Desktop.
新・明解Java入門 演習3-17
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