Day 2 Stept 5

This commit is contained in:
2026-09-09 16:02:06 +09:00
parent d16b47bc60
commit 53d0b769aa

View File

@@ -0,0 +1,37 @@
package Day2;
import java.util.Scanner;
public class Day2_5 {
public static void main(String[] args) {
String[] messages = { "いまなにしてる", "何も入力されていません", "投稿文が長すぎます", "↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓" };
Scanner scan = new Scanner(System.in);
String str = "";
int maxLength = 140;
while (true) {
System.out.println(messages[0]);
str = scan.nextLine().replace(" ", "").replace(" ", "");
// 三項演算子 error message in shot the statement but this way is error race hight ( so just the study no using)
String errorMessage = str.isEmpty() ? messages[1]
: str.length() > maxLength ? messages[2] : null;
//null is need the end for root when check the statement that is reprecent for nothig any statement;
if (errorMessage != null) {
System.out.println(errorMessage);
continue;
}
break;
}
System.out.println();
System.out.println(messages[3]);
System.out.println(str);
scan.close();
}
}