From 6341b9900e4d35693a51e46dd2fd22b46f4d2f60 Mon Sep 17 00:00:00 2001 From: o-matsuda <26-o-matsuda-stellatecnica@it-college.co.jp> Date: Fri, 11 Sep 2026 16:13:57 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=AF=E3=82=A8=E3=82=B9=E3=83=81=E3=83=A7?= =?UTF-8?q?=E3=83=B3=EF=BC=95=E3=81=AE=EF=BC=92=E3=81=BE=E3=81=A7=E5=AE=8C?= =?UTF-8?q?=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Question05-switch/src/PTra05_01.java | 20 ++++++++++++++++++++ Question05-switch/src/PTra05_02.java | 21 +++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Question05-switch/src/PTra05_01.java b/Question05-switch/src/PTra05_01.java index 60e8a86..0978a7a 100644 --- a/Question05-switch/src/PTra05_01.java +++ b/Question05-switch/src/PTra05_01.java @@ -23,5 +23,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..83dea08 100644 --- a/Question05-switch/src/PTra05_02.java +++ b/Question05-switch/src/PTra05_02.java @@ -29,7 +29,24 @@ 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("計算に失敗しました"); + } } - }