3日目 段階1 小澤
This commit is contained in:
55
StringCheck/src/day3/StringCheck.java
Normal file
55
StringCheck/src/day3/StringCheck.java
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
package day3;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
|
||||||
|
public class StringCheck {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
String[] messages = {
|
||||||
|
"いまなにしてる?",
|
||||||
|
"何も入力されていません",
|
||||||
|
"投稿文が長すぎます",
|
||||||
|
"↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
String str = "";
|
||||||
|
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
System.out.println(messages[0]);
|
||||||
|
|
||||||
|
|
||||||
|
str = imputString();
|
||||||
|
|
||||||
|
boolean isEmpty = (str.length() == 0);
|
||||||
|
boolean isTooLong = (str.length() > 140);
|
||||||
|
|
||||||
|
|
||||||
|
if (isEmpty) {
|
||||||
|
System.out.println(messages[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isTooLong) {
|
||||||
|
System.out.println(messages[2]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
System.out.println(messages[3]);
|
||||||
|
System.out.println(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String imputString() {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
String line = scanner.nextLine();
|
||||||
|
return line.strip();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user