Day 2 Stept 5
This commit is contained in:
37
Exercises/src/Day2/Day2_5.java
Normal file
37
Exercises/src/Day2/Day2_5.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user