20261019
This commit is contained in:
@@ -1,22 +1,67 @@
|
||||
import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Question04_05 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
//勝敗
|
||||
boolean winFlag = false;
|
||||
|
||||
//最初の言葉
|
||||
System.out.println("じゃんけんを行います。、あなたの出す手を入力してください、0:グー, 1:チョキ, 2:パー");
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int select = sc.nextInt();
|
||||
int playerHand = select;
|
||||
|
||||
|
||||
|
||||
|
||||
while(true) {
|
||||
while(true) {
|
||||
//自分側の手
|
||||
System.out.println("じゃんけんを行います。、あなたの出す手を入力してください、0:グー, 1:チョキ, 2:パー");
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int select = sc.nextInt();
|
||||
int playerHand = select;
|
||||
|
||||
if(playerHand == 0) {
|
||||
System.out.println("あなたはグーを出しました");
|
||||
|
||||
} else if(playerHand == 1) {
|
||||
System.out.println("あなたはチョキを出しました");
|
||||
|
||||
} else {
|
||||
System.out.println("あなたはパーを出しました");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//コンピュータ側の手
|
||||
|
||||
// 1. Randomクラスのインスタンスを生成
|
||||
Random rand = new Random();
|
||||
|
||||
// 2. 乱数を取得するメソッドを呼ぶ
|
||||
int npcHand = rand.nextInt(2); // int型の範囲でランダムな整数
|
||||
|
||||
if(npcHand == 0) {
|
||||
System.out.println("相手はグーを出しました");
|
||||
|
||||
} else if(playerHand == 1) {
|
||||
System.out.println("相手はチョキを出しました");
|
||||
|
||||
} else {
|
||||
System.out.println("相手はパーを出しました");
|
||||
}
|
||||
|
||||
//勝敗を決める
|
||||
|
||||
if(playerHand == npcHand) {
|
||||
System.out.println("あいこです");
|
||||
continue;
|
||||
|
||||
} else if((playerHand == 0 && npcHand == 1) || (playerHand == 1 && npcHand == 2) || (playerHand == 2 && npcHand == 0)) {
|
||||
System.out.println("あなたの勝ちです");
|
||||
|
||||
} else {
|
||||
System.out.println("あなたの負けです");
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user