From 2c25236ae73a7d10f7cb9d421c918546e9fb1659 Mon Sep 17 00:00:00 2001
From: a-takayama <26-a-takayama-scm@it-college.co.jp>
Date: Fri, 11 Sep 2026 16:05:20 +0900
Subject: [PATCH] =?UTF-8?q?q4-1=E3=81=8B=E3=82=89q4-4=E3=81=BE=E3=81=A7?=
=?UTF-8?q?=E5=AE=8C=E4=BA=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Question04-while/.classpath | 6 ++++++
Question04-while/.gitignore | 1 +
Question04-while/.project | 17 +++++++++++++++++
Question04-while/src/PTra04_01.java | 7 +++++++
Question04-while/src/PTra04_02.java | 10 ++++++++++
Question04-while/src/PTra04_04.java | 18 ++++++++++++++----
6 files changed, 55 insertions(+), 4 deletions(-)
create mode 100644 Question04-while/.classpath
create mode 100644 Question04-while/.gitignore
create mode 100644 Question04-while/.project
diff --git a/Question04-while/.classpath b/Question04-while/.classpath
new file mode 100644
index 0000000..0cbf9cd
--- /dev/null
+++ b/Question04-while/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/Question04-while/.gitignore b/Question04-while/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/Question04-while/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/Question04-while/.project b/Question04-while/.project
new file mode 100644
index 0000000..b1eea3d
--- /dev/null
+++ b/Question04-while/.project
@@ -0,0 +1,17 @@
+
+
+ Question04-while
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/Question04-while/src/PTra04_01.java b/Question04-while/src/PTra04_01.java
index 08c2624..9768099 100644
--- a/Question04-while/src/PTra04_01.java
+++ b/Question04-while/src/PTra04_01.java
@@ -16,10 +16,17 @@ public class PTra04_01 {
// 以下のwhile文は0~9のランダムな値をコンソールに出力する処理を無限に繰り返します。
// TODO while文の条件を修正して5が出力されたら繰り返しを止めるようにしてください。
while(true) {
+
// 0~9のランダムな値を生成
randomNumber = random.nextInt(10);
// 生成した値をコンソールに出力
System.out.println(randomNumber);
+
+ boolean isOver = (randomNumber == 5);
+
+ if(isOver) {
+ break;
+ }
}
}
diff --git a/Question04-while/src/PTra04_02.java b/Question04-while/src/PTra04_02.java
index 4ce7b65..1469738 100644
--- a/Question04-while/src/PTra04_02.java
+++ b/Question04-while/src/PTra04_02.java
@@ -15,6 +15,16 @@ public class PTra04_02 {
* 繰り返しの中でnumを2倍した数値をnumに代入してください。
* ※ 繰り返しにはwhile文を用いてください
*/
+ while(true) {
+
+ num = (num * 2);
+
+ boolean isToom = (num >= 1000);
+ if(isToom) {
+ break;
+ }
+ System.out.println(num);
+ }
}
}
diff --git a/Question04-while/src/PTra04_04.java b/Question04-while/src/PTra04_04.java
index ecaa1fe..b5db0ff 100644
--- a/Question04-while/src/PTra04_04.java
+++ b/Question04-while/src/PTra04_04.java
@@ -18,13 +18,15 @@ public class PTra04_04 {
Random random = new Random();
// TODO 双六の総コマ数としてint型の変数mapを宣言し、50を代入してください。
+ int map = 50;
// TODO 現在までの進んだコマ数としてint型の変数progressを宣言し、0を代入してください。
-
+ int progress = 0;
+
System.out.println("===== START =====");
// TODO 変数mapとprogressを用いて、ゴールするまで繰り返すようにwhile文の条件を記述してください。
- while() {
+ while(true) {
// 入力を促すメッセージを出力し、エンターキーが押されるのを待ちます。
System.out.println("Enterキーを押してください。さいころをふります。");
scanner.nextLine();
@@ -34,11 +36,19 @@ public class PTra04_04 {
// TODO 変数diceを用いて、"#の目が出ました。"というメッセージを出力してください。
// ※ #には変数diceの値が入ります。
-
+ System.out.println(dice + "の目が出ました。");
// TODO 変数progressに変数diceの値を加算してください。
-
+ progress = progress + dice;
// TODO まだゴールしていない場合は"残りのマスは#マスです。"というメッセージを出力してください。
// ※ #には双六の残りのマス数が入ります。
+ if(progress < 50) {
+ System.out.println("残りのマスは" + (map - progress) + "マスです。");
+ }else if(progress > 50){
+ break;
+
+ }
+
+
}