最終日
This commit is contained in:
75
StringCheck20261013_平山.java
Normal file
75
StringCheck20261013_平山.java
Normal file
@@ -0,0 +1,75 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class StringCheck {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
String[] name = {"いまなにしてる?", "何も入力されていません", "投稿文が長すぎます","↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓"};
|
||||
|
||||
String str;
|
||||
|
||||
|
||||
while (true) {
|
||||
|
||||
System.out.println(name[0]);
|
||||
str = inputString();
|
||||
|
||||
if (str.length() == 0) {
|
||||
|
||||
System.out.println(name[1]);
|
||||
continue;
|
||||
|
||||
} else if (str.length() > 140) {
|
||||
|
||||
System.out.println(name[2]);
|
||||
continue;
|
||||
} else {
|
||||
System.out.println(str);
|
||||
|
||||
break;
|
||||
}}
|
||||
System.out.println(" ");
|
||||
|
||||
System.out.println(name[3]);
|
||||
|
||||
System.out.println(str);
|
||||
|
||||
System.out.println(140 - str.length());
|
||||
|
||||
//0を超える文字数
|
||||
System.out.println(0 <= str.length());
|
||||
|
||||
//140文字未満
|
||||
System.out.println(str.length() <= 140);
|
||||
}
|
||||
|
||||
//空白除去
|
||||
public static String inputString() {
|
||||
//標準入力を読み込む準備をする
|
||||
Scanner sc = new Scanner(System.in);
|
||||
//一行分の文字列を読み込む
|
||||
String str = sc.nextLine();
|
||||
//読み込んだ文字列の前後にある空白を取り除く
|
||||
return str.strip();
|
||||
}
|
||||
|
||||
//空文字判定
|
||||
public static boolean isEmptyInput(String str) {
|
||||
|
||||
if (str.length() == 0) {
|
||||
return ;
|
||||
System.out.println(name[1]);
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//文字数超過判定
|
||||
//public static String isTooLongInput() {
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user