From 9a78905b5ffd1887e838cc39132ff83ae3f54e54 Mon Sep 17 00:00:00 2001 From: y-nakano <26-y-nakano-tmn@it-college.co.jp> Date: Thu, 10 Sep 2026 16:16:59 +0900 Subject: [PATCH] =?UTF-8?q?=E6=AE=B5=E9=9A=8E=EF=BC=92=E3=81=A7=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PJ/src/day3/StringCheck.java | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/PJ/src/day3/StringCheck.java b/PJ/src/day3/StringCheck.java index ac5cdc9..a734c8c 100644 --- a/PJ/src/day3/StringCheck.java +++ b/PJ/src/day3/StringCheck.java @@ -78,13 +78,13 @@ public class StringCheck { // 1日目の時点ではif文がまだ使えなかったため、この2つの真偽値は // 画面に表示して目視確認するだけだった。 // 2日目からは、この真偽値をそのままif文の条件として使う。 - boolean isEmpty = (str.length() == 0); - boolean isTooLong = (str.length() > 140); + //boolean isEmpty = (str.length() == 0); + //boolean isTooLong = (str.length() > 140); // ============================================================ // 2日目 段階2:if文による検証ロジック // ============================================================ - if (isEmpty) { + if (isEmptyInput(str)) { // 何も入力されていない(または空白のみ入力された)場合 System.out.println(messages[1]); // continue で、while文の先頭(プロンプト表示)に戻り、 @@ -92,7 +92,7 @@ public class StringCheck { continue; } - if (isTooLong) { + if (isTooLongInput(str)) { // 141文字以上入力された場合 System.out.println(messages[2]); // continue で、while文の先頭に戻る。 @@ -119,7 +119,18 @@ public class StringCheck { // キーボードから1行分の文字列を読み取る。 String line = scanner.nextLine(); // 読み取った文字列の前後にある空白文字(半角スペース・全角スペース - // など)を取り除き、str に格納する。 + // など)を取り除き、str に格納する。 return line.strip(); } -} + + public static boolean isEmptyInput(String str) { + boolean isEmpty = (str.length() == 0); + return isEmpty; + } + + public static boolean isTooLongInput(String str) { + boolean isTooLong = (str.length() > 140); + return isTooLong; + } + +} \ No newline at end of file