From f96807736e4640864e98704282ef85b800d5adfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=93=A6=E3=80=80=E6=98=B4=E4=B8=96?= <26-k-kawara-rootship@it-college.co.jp> Date: Fri, 30 Oct 2026 15:27:20 +0900 Subject: [PATCH] 15:27 --- Question04-while/src/main/java/Q4_4.java | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Question04-while/src/main/java/Q4_4.java diff --git a/Question04-while/src/main/java/Q4_4.java b/Question04-while/src/main/java/Q4_4.java new file mode 100644 index 0000000..3758f99 --- /dev/null +++ b/Question04-while/src/main/java/Q4_4.java @@ -0,0 +1,35 @@ + +import java.util.Random; +import java.util.Scanner; + +public class Q4_4 { + public static void main(String[] args) { + + int map = 50; + int progress = 0; + + Random random = new Random(); + Scanner scanner = new Scanner(System.in); + + System.out.println("===== START ====="); + + while (progress < map) { + System.out.print("Enterキーを押してください。さいころをふります。"); + scanner.nextLine(); + + int dice = random.nextInt(6) + 1; + System.out.println(dice + "の目が出ました。"); + + progress += dice; + + if (progress < map) { + int remaining = map - progress; + System.out.println("残りのマスは" + remaining + "マスです。"); + } + } + + System.out.println("===== GOAL ====="); + scanner.close(); + } + +}