From fb3dd4e9a97bd4200a350e2705b19da2cb952864 Mon Sep 17 00:00:00 2001 From: t-eguchi <26-t-eguchi-tmn@it-college.co.jp> Date: Fri, 11 Sep 2026 16:31:58 +0900 Subject: [PATCH] =?UTF-8?q?Q5=E7=B5=82=E3=82=8F=E3=82=8A=E3=81=BE=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Question05-switch/src/PTra05_01.java | 28 +++++++++++++++++++++++++++- Question05-switch/src/PTra05_02.java | 20 ++++++++++++++++++++ Question05-switch/src/PTra05_03.java | 18 ++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/Question05-switch/src/PTra05_01.java b/Question05-switch/src/PTra05_01.java index 60e8a86..3c0b9b0 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,32 @@ 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..992c3ff 100644 --- a/Question05-switch/src/PTra05_02.java +++ b/Question05-switch/src/PTra05_02.java @@ -29,6 +29,26 @@ 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..d97a817 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(myCard >= dealerCard) { + System.out.println("あなたの勝ちです"); + }else { + System.out.println("あなたの負けです"); + } + break; + case "L": + if(myCard <= dealerCard) { + System.out.println("あなたの価値です"); + }else { + System.out.println("あなたの負けです"); + } + break; + default: + System.out.println("不正な値が入力されました"); } } +}