Created
July 18, 2013 17:17
-
-
Save shikajiro/6031123 to your computer and use it in GitHub Desktop.
0,1,2の数字を使ってジャンケンプログラムを作ってください。 0ならパー、1ならチョキ、2ならグーとしてください。 Randomを使って0から2まで生成させてください。 Scannerを使ってユーザーからの入力を受け付けてください。
Randomで生成した値と、Scannerでユーザーから受け付けた値を比較してください。 比較した結果の勝敗に応じて、"あなたの勝ちです。"、"あなたの負けです。"、"あいこです。"と表示させてください。
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
public class HomeWork { | |
public static void main(String[] args) { | |
int random = new Random().nextInt(3); | |
int input = new Scanner(System.in).nextInt(); | |
if (random == input) { | |
// 同じならあいこ | |
System.out.println("あいこです。"); | |
} else { | |
if (input == 0) { | |
// もし自分がパーだったら | |
if (random == 1) {//相手はチョキ | |
System.out.println("あなたの負けです。"); | |
} else { | |
System.out.println("あなたの勝ちです。"); | |
} | |
} else if (input == 1) { | |
// もし自分がチョキだったら | |
if (random == 0) {//相手はパー | |
System.out.println("あなたの勝ちです。"); | |
} else { | |
System.out.println("あなたの負けです。"); | |
} | |
} else if (input == 2) { | |
// もし自分がグーだったら | |
if (random == 0) {//相手はパー | |
System.out.println("あなたの負けです。"); | |
} else { | |
System.out.println("あなたの勝ちです。"); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment