q4-5まで完了

This commit is contained in:
2026-09-11 16:39:12 +09:00
parent 2c25236ae7
commit 6dcc784838
3 changed files with 37 additions and 4 deletions

View File

@@ -22,6 +22,7 @@ public class PTra04_03 {
// 生成した値をコンソールに出力
System.out.println(randomNumber);
}
}
}

View File

@@ -43,13 +43,14 @@ public class PTra04_04 {
// ※ #には双六の残りのマス数が入ります。
if(progress < 50) {
System.out.println("残りのマスは" + (map - progress) + "マスです。");
}else if(progress > 50){
}else if(progress >= 50){
break;
}
}
System.out.println("===== GOAL =====");

View File

@@ -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();
}
}
}