From 1603b2c7532435d4675ec7dc904d0742b2cc9e8e Mon Sep 17 00:00:00 2001 From: y-nakano <26-y-nakano-tmn@it-college.co.jp> Date: Fri, 11 Sep 2026 16:13:23 +0900 Subject: [PATCH] =?UTF-8?q?question5=E3=81=A7=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Question05-switch/src/PTra05_01.java | 21 ++++++++++++++++++++- Question05-switch/src/PTra05_02.java | 19 +++++++++++++++++++ Question05-switch/src/PTra05_03.java | 20 +++++++++++++++++++- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/Question05-switch/src/PTra05_01.java b/Question05-switch/src/PTra05_01.java index 60e8a86..9d23245 100644 --- a/Question05-switch/src/PTra05_01.java +++ b/Question05-switch/src/PTra05_01.java @@ -11,7 +11,6 @@ public class PTra05_01 { // ランダムな数値をnumに代入します。範囲は 0 ~ 5 です。 int num = new java.util.Random().nextInt(6); - // TODO 以下の条件に沿ったプログラムを記述してください // ※ switch文を使用してプログラムを記述してください /* @@ -23,5 +22,25 @@ public class PTra05_01 { * 変数numの値が 4 の場合 -> あなたの運勢は「末吉」です * 変数numの値が 5 の場合 -> あなたの運勢は「凶」です */ + switch (num) { + case 0: + System.out.println("あなたの運勢は「大吉」です"); + break; + case 1: + System.out.println("あなたの運勢は「吉」です"); + break; + case 2: + System.out.println("あなたの運勢は「中吉」です"); + break; + case 3: + System.out.println("あなたの運勢は「小吉」です"); + break; + case 4: + System.out.println("あなたの運勢は「末吉」です"); + break; + case 5: + System.out.println("あなたの運勢は「凶」です"); + break; + } } } diff --git a/Question05-switch/src/PTra05_02.java b/Question05-switch/src/PTra05_02.java index 1b059ad..2b57bf5 100644 --- a/Question05-switch/src/PTra05_02.java +++ b/Question05-switch/src/PTra05_02.java @@ -29,6 +29,25 @@ public class PTra05_02 { * 変数choiceの値が % の場合 -> num1 を num2 で 割った余り を出力 * 変数choiceの値が 上記以外 の場合 -> 計算に失敗しました を出力 */ + switch (choice) { + case "+": + System.out.println(num1 + num2); + break; + case "-": + System.out.println(num1 - num2); + break; + case "*": + System.out.println(num1 * num2); + break; + case "/": + System.out.println(num1 / num2); + break; + case "%": + System.out.println(num1 % num2); + break; + default: + System.out.println("計算に失敗しました"); + } } diff --git a/Question05-switch/src/PTra05_03.java b/Question05-switch/src/PTra05_03.java index 41cf99b..6e27f9f 100644 --- a/Question05-switch/src/PTra05_03.java +++ b/Question05-switch/src/PTra05_03.java @@ -42,6 +42,24 @@ public class PTra05_03 { // TODO 予想が当たった場合は「あなたの勝ちです」、外れた場合は「あなたの負けです」を出力してください。 // ※ H か L 以外の文字が入力された場合は、「不正な値が入力されました」と出力してください。 + switch (judgement) { + case "H": + if (dealerCard <= myCard) { + System.out.println("あなたの勝ちです"); + } else { + System.out.println("あなたの負けです"); + } + break; + case "L": + if (dealerCard >= myCard) { + System.out.println("あなたの勝ちです"); + } else { + System.out.println("あなたの負けです"); + } + break; + default: + System.out.println("不正な数値が入力されました"); + } } -} +} \ No newline at end of file