段階3終わりました

This commit is contained in:
2026-09-09 15:20:57 +09:00
parent a8ba4e4098
commit dc289e7821

View File

@@ -15,16 +15,20 @@ public class StringCheck {
//標準入力から1行分の文字列を読み込む //標準入力から1行分の文字列を読み込む
Scanner scan = new Scanner(System.in); Scanner scan = new Scanner(System.in);
String str = "";
while (true) { while (true) {
System.out.println(classNames[0]); System.out.println(classNames[0]);
str = scan.nextLine();
String str = scan.nextLine(); // 前後の空白を除去した文字列
String trimmed = str.strip();
// 文字列の長さを取得 // 文字列の長さを取得
int length = str.length(); int length = trimmed.length();
// 空字判定 // 空字判定(空白だけも含む)
boolean isEmpty = (length == 0); boolean isEmpty = (length == 0);
// 文字数超過判定 // 文字数超過判定
@@ -33,28 +37,24 @@ public class StringCheck {
// 残り入力可能文字数 // 残り入力可能文字数
int a = (140 - length); int a = (140 - length);
System.out.println();
System.out.println(classNames[3]);
//読み込んだ文字列の前後にある空白文字を除去
System.out.println(str.strip());
// if文による検証ロジック // if文による検証ロジック
if (isEmpty) { if (isEmpty) {
System.out.println("何も入力されていません"); System.out.println(classNames[1]);
continue; continue;
} else if (isOverLimit) { } else if (isOverLimit) {
System.out.println("投稿文が長すぎます"); System.out.println(classNames[2]);
continue; continue;
} else { } else {
break; break;
} }
}
}
System.out.println();
System.out.println(classNames[3]);
//読み込んだ文字列の前後にある空白文字を除去
System.out.println(str.strip());
scan.close();
} }