段階2です
This commit is contained in:
@@ -78,13 +78,13 @@ public class StringCheck {
|
||||
// 1日目の時点ではif文がまだ使えなかったため、この2つの真偽値は
|
||||
// 画面に表示して目視確認するだけだった。
|
||||
// 2日目からは、この真偽値をそのままif文の条件として使う。
|
||||
boolean isEmpty = (str.length() == 0);
|
||||
boolean isTooLong = (str.length() > 140);
|
||||
//boolean isEmpty = (str.length() == 0);
|
||||
//boolean isTooLong = (str.length() > 140);
|
||||
|
||||
// ============================================================
|
||||
// 2日目 段階2:if文による検証ロジック
|
||||
// ============================================================
|
||||
if (isEmpty) {
|
||||
if (isEmptyInput(str)) {
|
||||
// 何も入力されていない(または空白のみ入力された)場合
|
||||
System.out.println(messages[1]);
|
||||
// continue で、while文の先頭(プロンプト表示)に戻り、
|
||||
@@ -92,7 +92,7 @@ public class StringCheck {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isTooLong) {
|
||||
if (isTooLongInput(str)) {
|
||||
// 141文字以上入力された場合
|
||||
System.out.println(messages[2]);
|
||||
// continue で、while文の先頭に戻る。
|
||||
@@ -119,7 +119,18 @@ public class StringCheck {
|
||||
// キーボードから1行分の文字列を読み取る。
|
||||
String line = scanner.nextLine();
|
||||
// 読み取った文字列の前後にある空白文字(半角スペース・全角スペース
|
||||
// など)を取り除き、str に格納する。
|
||||
// など)を取り除き、str に格納する。
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user