段階2です

This commit is contained in:
2026-09-10 16:16:59 +09:00
parent e9bc08ff77
commit 9a78905b5f

View File

@@ -78,13 +78,13 @@ public class StringCheck {
// 1日目の時点ではif文がまだ使えなかったため、この2つの真偽値は // 1日目の時点ではif文がまだ使えなかったため、この2つの真偽値は
// 画面に表示して目視確認するだけだった。 // 画面に表示して目視確認するだけだった。
// 2日目からは、この真偽値をそのままif文の条件として使う。 // 2日目からは、この真偽値をそのままif文の条件として使う。
boolean isEmpty = (str.length() == 0); //boolean isEmpty = (str.length() == 0);
boolean isTooLong = (str.length() > 140); //boolean isTooLong = (str.length() > 140);
// ============================================================ // ============================================================
// 2日目 段階2:if文による検証ロジック // 2日目 段階2:if文による検証ロジック
// ============================================================ // ============================================================
if (isEmpty) { if (isEmptyInput(str)) {
// 何も入力されていない(または空白のみ入力された)場合 // 何も入力されていない(または空白のみ入力された)場合
System.out.println(messages[1]); System.out.println(messages[1]);
// continue で、while文の先頭(プロンプト表示)に戻り、 // continue で、while文の先頭(プロンプト表示)に戻り、
@@ -92,7 +92,7 @@ public class StringCheck {
continue; continue;
} }
if (isTooLong) { if (isTooLongInput(str)) {
// 141文字以上入力された場合 // 141文字以上入力された場合
System.out.println(messages[2]); System.out.println(messages[2]);
// continue で、while文の先頭に戻る。 // continue で、while文の先頭に戻る。
@@ -122,4 +122,15 @@ public class StringCheck {
// など)を取り除き、str に格納する。 // など)を取り除き、str に格納する。
return line.strip(); 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;
}
} }