Day2 stept 4

This commit is contained in:
2026-09-09 15:19:17 +09:00
parent e8bdd3f18a
commit d16b47bc60

View File

@@ -12,42 +12,37 @@ public class StringCheck {
//int maxLength = 140; //int maxLength = 140;
// 段階1: 無限ループ化 // 段階1: 無限ループ化
while (true) { while (true) {
System.out.println(messages[0]); System.out.println(messages[0]);
str = scan.nextLine(); str = scan.nextLine();
//str = scan.nextLine().trim(); //str = scan.nextLine().trim();
str = str.replaceAll("[\\s ]", ""); str = str.replaceAll("[\\s ]", "");
//String str1 = str.replaceAll("[  ]", ""); //String str1 = str.replaceAll("[  ]", "");
//System.out.println("あなたの入力は: [" + str + "]"); //System.out.println("あなたの入力は: [" + str + "]");
//2段階のif
//2段階のif boolean isEmpty = str.isEmpty();
boolean isEmpty = str.isEmpty(); boolean isTooLong = str.length() > 140;
boolean isTooLong = str.length() > 140;
if (isEmpty) {
if(isEmpty) { System.out.println(messages[1]);
System.out.println(messages[1]); continue;
continue; }
}
//(Length check) 140 under //(Length check) 140 under
if (isTooLong) {
System.out.println(messages[2]);
continue;
}
if (isTooLong) {
break; System.out.println(messages[2]);
} continue;
System.out.println(); }
System.out.println(messages[3]);
System.out.println(str);
scan.close();
break;
}
System.out.println();
System.out.println(messages[3]);
System.out.println(str);
scan.close();
}
} }
}