3日目
This commit is contained in:
76
StringCheck20061009_瓦.java
Normal file
76
StringCheck20061009_瓦.java
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class StringCheck {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
String[] main;
|
||||||
|
|
||||||
|
main = new String[4];
|
||||||
|
|
||||||
|
main[0] = "いまなにしてる?";
|
||||||
|
main[1] = "何も入力されていません";
|
||||||
|
main[2] = "投稿文が長すぎます";
|
||||||
|
main[3] = "↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(main[0]);
|
||||||
|
|
||||||
|
System.out.println("");
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
String str = scanner.nextLine();
|
||||||
|
str = str.replace(" ","").replace(" ","");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("");
|
||||||
|
|
||||||
|
System.out.println("");
|
||||||
|
|
||||||
|
int length = str.length();
|
||||||
|
|
||||||
|
boolean isEmpty = length == 0;
|
||||||
|
|
||||||
|
boolean isTooLong = length >= 140;
|
||||||
|
|
||||||
|
int remaining = 140 - length;
|
||||||
|
System.out.println("残りの文字数" + remaining);
|
||||||
|
|
||||||
|
|
||||||
|
if (isEmpty) {
|
||||||
|
System.out.println("何も入力されていません");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(isTooLong) {
|
||||||
|
System.out.println("投稿文が長すぎます");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("");
|
||||||
|
|
||||||
|
System.out.println(main[3]);
|
||||||
|
|
||||||
|
System.out.println(str);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
scanner.close();
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user