diff --git a/Question04-while/src/PTra04_03.java b/Question04-while/src/PTra04_03.java index 21b7f8e..9ce94fa 100644 --- a/Question04-while/src/PTra04_03.java +++ b/Question04-while/src/PTra04_03.java @@ -21,6 +21,7 @@ public class PTra04_03 { randomNumber = random.nextInt(10); // 生成した値をコンソールに出力 System.out.println(randomNumber); + } } diff --git a/Question04-while/src/PTra04_04.java b/Question04-while/src/PTra04_04.java index b5db0ff..253d693 100644 --- a/Question04-while/src/PTra04_04.java +++ b/Question04-while/src/PTra04_04.java @@ -43,12 +43,13 @@ public class PTra04_04 { // ※ #には双六の残りのマス数が入ります。 if(progress < 50) { System.out.println("残りのマスは" + (map - progress) + "マスです。"); - }else if(progress > 50){ + }else if(progress >= 50){ break; } + } diff --git a/Question04-while/src/PTra04_05.java b/Question04-while/src/PTra04_05.java index 2b15402..6378a65 100644 --- a/Question04-while/src/PTra04_05.java +++ b/Question04-while/src/PTra04_05.java @@ -32,16 +32,47 @@ public class PTra04_05 { System.out.println("0:グー, 1:チョキ, 2:パー"); playerHand = Integer.parseInt(scanner.nextLine()); // TODO 選ばれた手を出力してください(0なら"あなたはグーを出しました"等) + if(playerHand ==0) { + System.out.println("あなたはグーを出しました"); + }if(playerHand == 1) { + System.out.println("あなたはチョキを出しました。"); + }else if(playerHand == 2){ + System.out.println("あなたはパーを出しました。"); + } // 対戦相手の手をランダムに選択する。 npcHand = random.nextInt(3); // TODO 対戦相手の手を出力してください(0なら"相手はグーを出しました"等) - + if(npcHand ==0) { + System.out.println("相手はグーを出しました"); + }if(npcHand == 1) { + System.out.println("相手はチョキを出しました。"); + }else if(npcHand == 2){ + System.out.println("相手はパーを出しました。"); + } // TODO じゃんけんの結果を出力し、プレイヤーが勝った場合はプログラムが終了するようにしてください。 - + String result; + if(playerHand == npcHand) { + result = "あいこです。"; + }else if( + (playerHand == 0 && npcHand == 1)|| //プレイヤグー・相手チョキ + (playerHand == 1 && npcHand == 2)|| //チョキ・パー + (playerHand == 2 && npcHand == 0) //パー・チョキ + ) { + result = "あなたの勝ち"; + System.out.println("結果 : " + result); + break; + }else { + result = "あなたの負け"; + } + + System.out.println("結果 : " + result); + + } + + // 次のじゃんけんの前に改行しておく System.out.println(); } } -}