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