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
boolean isEmpty = str.isEmpty();
boolean isTooLong = str.length() > 140;
//2段階のif if (isEmpty) {
boolean isEmpty = str.isEmpty(); System.out.println(messages[1]);
boolean isTooLong = str.length() > 140; continue;
}
if(isEmpty) {
System.out.println(messages[1]);
continue;
}
//(Length check) 140 under //(Length check) 140 under
if (isTooLong) { if (isTooLong) {
System.out.println(messages[2]); System.out.println(messages[2]);
continue; continue;
} }
break;
}
System.out.println();
System.out.println(messages[3]);
System.out.println(str);
break; scan.close();
}
System.out.println();
System.out.println(messages[3]);
System.out.println(str);
scan.close();
}
} }
}