From 53d0b769aae51c9c62fa020e96d0739a21e24e01 Mon Sep 17 00:00:00 2001 From: "h.hein" <26-h-kyaw-sakuracommunication@it-college.co.jp> Date: Wed, 9 Sep 2026 16:02:06 +0900 Subject: [PATCH] Day 2 Stept 5 --- Exercises/src/Day2/Day2_5.java | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Exercises/src/Day2/Day2_5.java diff --git a/Exercises/src/Day2/Day2_5.java b/Exercises/src/Day2/Day2_5.java new file mode 100644 index 0000000..12cd174 --- /dev/null +++ b/Exercises/src/Day2/Day2_5.java @@ -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(); + } +}