From a8ba4e40983f16a53e54ee8eed7358448ea6ad05 Mon Sep 17 00:00:00 2001 From: t-eguchi <26-t-eguchi-tmn@it-college.co.jp> Date: Wed, 9 Sep 2026 13:57:43 +0900 Subject: [PATCH] =?UTF-8?q?=E6=AE=B5=E9=9A=8E=EF=BC=92=E7=B5=82=E3=82=8F?= =?UTF-8?q?=E3=82=8A=E3=81=BE=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StringCheck/src/StringCheck.java | 65 +++++++++++++++++--------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/StringCheck/src/StringCheck.java b/StringCheck/src/StringCheck.java index 94c1ecd..e7bfe04 100644 --- a/StringCheck/src/StringCheck.java +++ b/StringCheck/src/StringCheck.java @@ -15,44 +15,47 @@ public class StringCheck { //標準入力から1行分の文字列を読み込む Scanner scan = new Scanner(System.in); - - while(true) { - - System.out.println(classNames[0]); - - String str = scan.nextLine(); - + while (true) { + + System.out.println(classNames[0]); + + String str = scan.nextLine(); + + // 文字列の長さを取得 + int length = str.length(); + + // 空字判定 + boolean isEmpty = (length == 0); + + // 文字数超過判定 + boolean isOverLimit = (length > 140); + + // 残り入力可能文字数 + int a = (140 - length); + - // 文字列の長さを取得 - int length = str.length(); - // 空字判定 - boolean isEmpty = (length == 0); + System.out.println(); + System.out.println(classNames[3]); - // 文字数超過判定 - boolean isOverLimit = (length > 140); + //読み込んだ文字列の前後にある空白文字を除去 + System.out.println(str.strip()); + + + // if文による検証ロジック + if (isEmpty) { + System.out.println("何も入力されていません"); + continue; + } else if (isOverLimit) { + System.out.println("投稿文が長すぎます"); + continue; + } else { + break; - // 残り入力可能文字数 - int a = (140 - length); + } - System.out.println(); - System.out.println(classNames[3]); - - //読み込んだ文字列の前後にある空白文字を除去 - System.out.println(str.strip()); - - } - - - - // for-each練習 -// for (String name : classNames) { -// System.out.println(name); -// } - - } }