49 lines
1.1 KiB
Java
49 lines
1.1 KiB
Java
package Day2;
|
|
|
|
import java.util.Scanner;
|
|
|
|
public class StringCheck {
|
|
|
|
public static void main(String[] args) {
|
|
String[] messages = { "いまなにしてる", "何も入力されていません", "投稿文が長すぎます", "↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓" };
|
|
|
|
Scanner scan = new Scanner(System.in);
|
|
String str = "";
|
|
//int maxLength = 140;
|
|
|
|
// 段階1: 無限ループ化
|
|
while (true) {
|
|
System.out.println(messages[0]);
|
|
str = scan.nextLine().trim();
|
|
//System.out.println("あなたの入力は: [" + str + "]");
|
|
|
|
|
|
//2段階のif
|
|
boolean isEmpty = str.isEmpty();
|
|
boolean isTooLong = str.length() > 140;
|
|
if(isEmpty) {
|
|
System.out.println(messages[1]);
|
|
continue;
|
|
}
|
|
//(Length check) 140 under
|
|
|
|
if (isTooLong) {
|
|
System.out.println(messages[2]);
|
|
continue;
|
|
}
|
|
|
|
|
|
break;
|
|
}
|
|
System.out.println();
|
|
System.out.println(messages[3]);
|
|
System.out.println(str);
|
|
|
|
scan.close();
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|