From 0968140ed331807b90d37c30c94ddb0b8ccee559 Mon Sep 17 00:00:00 2001 From: m_ozawa <26-m-ozawa-swnet@it-college.co.jp> Date: Thu, 17 Sep 2026 16:49:51 +0900 Subject: [PATCH] Q5 --- Question05-switch/src/PTra05_01.java | 22 ++++++++++++++++++++++ Question05-switch/src/PTra05_02.java | 24 +++++++++++++++++++++++- Question05-switch/src/PTra05_03.java | 21 +++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/Question05-switch/src/PTra05_01.java b/Question05-switch/src/PTra05_01.java index 60e8a86..47aa933 100644 --- a/Question05-switch/src/PTra05_01.java +++ b/Question05-switch/src/PTra05_01.java @@ -23,5 +23,27 @@ 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..41b71ca 100644 --- a/Question05-switch/src/PTra05_02.java +++ b/Question05-switch/src/PTra05_02.java @@ -29,7 +29,29 @@ 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..a5a6061 100644 --- a/Question05-switch/src/PTra05_03.java +++ b/Question05-switch/src/PTra05_03.java @@ -42,6 +42,27 @@ public class PTra05_03 { // TODO 予想が当たった場合は「あなたの勝ちです」、外れた場合は「あなたの負けです」を出力してください。 // ※ H か L 以外の文字が入力された場合は、「不正な値が入力されました」と出力してください。 + switch(judgement) { + case "H": + if(myCard>dealerCard) { + System.out.println("あなたの勝ちです"); + break; + } + if(myCarddealerCard) { + System.out.println("あなたの負けです"); + break; + } } + } }