From 920c1d5303ea980f19e93075bdc5ac41a930cbed Mon Sep 17 00:00:00 2001 From: a-takayama <26-a-takayama-scm@it-college.co.jp> Date: Thu, 17 Sep 2026 16:39:23 +0900 Subject: [PATCH] =?UTF-8?q?q6-6=E3=81=BE=E3=81=A7=E5=AE=8C=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Question05-switch/src/PTra05_01.java | 1 + Question05-switch/src/PTra05_02.java | 21 +++++++++++++++++++++ Question05-switch/src/PTra05_03.java | 27 +++++++++++++++++++++++++++ Question06-for/.classpath | 6 ++++++ Question06-for/.gitignore | 1 + Question06-for/.project | 17 +++++++++++++++++ Question06-for/src/PTra06_01.java | 4 ++++ Question06-for/src/PTra06_02.java | 4 ++++ Question06-for/src/PTra06_03.java | 4 ++++ Question06-for/src/PTra06_04.java | 12 ++++++++++++ Question06-for/src/PTra06_05.java | 9 ++++++--- Question06-for/src/PTra06_06.java | 11 +++++++++-- 12 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 Question06-for/.classpath create mode 100644 Question06-for/.gitignore create mode 100644 Question06-for/.project diff --git a/Question05-switch/src/PTra05_01.java b/Question05-switch/src/PTra05_01.java index 3c27b5a..330df01 100644 --- a/Question05-switch/src/PTra05_01.java +++ b/Question05-switch/src/PTra05_01.java @@ -1,3 +1,4 @@ + /* * PTra05_01.java * 作成 Rhizome diff --git a/Question05-switch/src/PTra05_02.java b/Question05-switch/src/PTra05_02.java index 1b059ad..d55c0af 100644 --- a/Question05-switch/src/PTra05_02.java +++ b/Question05-switch/src/PTra05_02.java @@ -29,6 +29,27 @@ 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); + default: + System.out.println("計算に失敗しました"); + + + } + } diff --git a/Question05-switch/src/PTra05_03.java b/Question05-switch/src/PTra05_03.java index 41cf99b..2b4f852 100644 --- a/Question05-switch/src/PTra05_03.java +++ b/Question05-switch/src/PTra05_03.java @@ -43,5 +43,32 @@ public class PTra05_03 { // TODO 予想が当たった場合は「あなたの勝ちです」、外れた場合は「あなたの負けです」を出力してください。 // ※ H か L 以外の文字が入力された場合は、「不正な値が入力されました」と出力してください。 + String result; + switch (judgement) { + case "H": + if (myCard >= dealerCard) { + System.out.println("あなたの勝ちです"); + } else if (myCard < dealerCard) { + System.out.println("あなたの負けです"); + } + break; + // }else if(myCard == dealerCard) { + // System.out.println(); + // } + + case "L": + if (myCard <= dealerCard) { + System.out.println("あなたの勝ちです"); + } else if (myCard > dealerCard) { + System.out.println("あなたの負けです"); + } + break; + default: + System.out.println("不正な値が入力されました"); + break; + + } + } + } diff --git a/Question06-for/.classpath b/Question06-for/.classpath new file mode 100644 index 0000000..0cbf9cd --- /dev/null +++ b/Question06-for/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Question06-for/.gitignore b/Question06-for/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Question06-for/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Question06-for/.project b/Question06-for/.project new file mode 100644 index 0000000..82b501b --- /dev/null +++ b/Question06-for/.project @@ -0,0 +1,17 @@ + + + Question06-for + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Question06-for/src/PTra06_01.java b/Question06-for/src/PTra06_01.java index cf38e18..91d9fc4 100644 --- a/Question06-for/src/PTra06_01.java +++ b/Question06-for/src/PTra06_01.java @@ -7,6 +7,10 @@ public class PTra06_01 { public static void main(String[] args) { // TODO for文を使って0から99までの整数を順にコンソールに出力してください。 + + for(int i = 0; i <= 99; i++){ + System.out.println(i); + } } } diff --git a/Question06-for/src/PTra06_02.java b/Question06-for/src/PTra06_02.java index e532445..dfa63fa 100644 --- a/Question06-for/src/PTra06_02.java +++ b/Question06-for/src/PTra06_02.java @@ -10,6 +10,10 @@ public class PTra06_02 { /* * ■■■■■ */ + for(int i = 0; i < 5; i++) { + System.out.print("■"); + } + System.out.println(); } diff --git a/Question06-for/src/PTra06_03.java b/Question06-for/src/PTra06_03.java index 4386054..008c873 100644 --- a/Question06-for/src/PTra06_03.java +++ b/Question06-for/src/PTra06_03.java @@ -9,6 +9,10 @@ public class PTra06_03 { // iが0から100になるまで繰り返しを行います for (int i = 0; i <= 100; i++) { + if(i % 2 == 0){ + System.out.println(i); + } + // TODO iが偶数の時だけ、iの値を出力してください diff --git a/Question06-for/src/PTra06_04.java b/Question06-for/src/PTra06_04.java index 8a947f3..07106d8 100644 --- a/Question06-for/src/PTra06_04.java +++ b/Question06-for/src/PTra06_04.java @@ -14,6 +14,18 @@ public class PTra06_04 { * ④ 上記のいずれにも当てはまらない場合はiの値をそのまま出力する */ for(int i = 1;i < 50;i++) { + if(i % 3 == 0) { + System.out.println("fizz"); //①処理 + } + if(i % 5 == 0) { + System.out.println("buzz"); //②処理 + } + if(i % 3 == 0 && i % 5 == 0) { + System.out.println("fizzbuzz"); //③処理 + } + else { + System.out.println(i); //④処理 + } } diff --git a/Question06-for/src/PTra06_05.java b/Question06-for/src/PTra06_05.java index 191bbb0..78c9d33 100644 --- a/Question06-for/src/PTra06_05.java +++ b/Question06-for/src/PTra06_05.java @@ -17,9 +17,12 @@ public class PTra06_05 { // TODO 値が2の場合は出力しないようにしてください。 // ※ continueを用いてください。 for(int i = 0;i < 10;i++) { - randomNumber = random.nextInt(3); - - + randomNumber = random.nextInt(3);{ + if(randomNumber == 2) { + continue; + } +// System.out.println(randomNumber); + } System.out.println(randomNumber); } } diff --git a/Question06-for/src/PTra06_06.java b/Question06-for/src/PTra06_06.java index 02b2f42..7db2d50 100644 --- a/Question06-for/src/PTra06_06.java +++ b/Question06-for/src/PTra06_06.java @@ -6,6 +6,7 @@ */ public class PTra06_06 { public static void main(String[] args) { + int rows = 5; // TODO for文を使って以下の出力結果が出るようなプログラムを作成してください。 /* * ■■■■■ @@ -14,7 +15,13 @@ public class PTra06_06 { * ■■■■■ * ■■■■■ */ - + for(int i = 0; i < rows; i++) { + for(int j = 0; j < rows; j++) { + System.out.print("■"); + } +// for(int i = 0; i <5; i++) { + System.out.println("■"); + } } - } +//for(int i = 0; i <5; i++) { \ No newline at end of file