段階2終わりました

This commit is contained in:
2026-09-09 13:57:43 +09:00
parent 0efa10e7df
commit a8ba4e4098

View File

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