段階3終わりました
This commit is contained in:
@@ -15,16 +15,20 @@ public class StringCheck {
|
||||
//標準入力から1行分の文字列を読み込む
|
||||
Scanner scan = new Scanner(System.in);
|
||||
|
||||
String str = "";
|
||||
|
||||
while (true) {
|
||||
|
||||
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);
|
||||
|
||||
// 文字数超過判定
|
||||
@@ -33,29 +37,25 @@ public class StringCheck {
|
||||
// 残り入力可能文字数
|
||||
int a = (140 - length);
|
||||
|
||||
|
||||
|
||||
System.out.println();
|
||||
System.out.println(classNames[3]);
|
||||
|
||||
//読み込んだ文字列の前後にある空白文字を除去
|
||||
System.out.println(str.strip());
|
||||
|
||||
|
||||
// if文による検証ロジック
|
||||
if (isEmpty) {
|
||||
System.out.println("何も入力されていません");
|
||||
System.out.println(classNames[1]);
|
||||
continue;
|
||||
} else if (isOverLimit) {
|
||||
System.out.println("投稿文が長すぎます");
|
||||
System.out.println(classNames[2]);
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
System.out.println(classNames[3]);
|
||||
//読み込んだ文字列の前後にある空白文字を除去
|
||||
System.out.println(str.strip());
|
||||
scan.close();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user