commit again
This commit is contained in:
38
Exercises/src/day_2/Day2_2.java
Normal file
38
Exercises/src/day_2/Day2_2.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package day_2;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Day2_2 {
|
||||
|
||||
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(" ", "");
|
||||
|
||||
// 早期リターン (Early Return / Guard Clause) ကို အသုံးပြု၍ ချက်ချင်းစစ်ဆေးခြင်း
|
||||
if (str.isEmpty()) {
|
||||
System.out.println(messages[1]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (str.length() > maxLength) {
|
||||
System.out.println(messages[2]);
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
System.out.println(messages[3]);
|
||||
System.out.println(str);
|
||||
|
||||
scan.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user