最終日提出
This commit is contained in:
@@ -1,35 +1,73 @@
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class StringCheack_20261009福森 {
|
public class StringCheack_20261009福森 {
|
||||||
|
|
||||||
|
|
||||||
|
//標準入力から1行読み込み、前後の空白を除去する処理のメソッド
|
||||||
|
public static String inputString(Scanner scanner) {
|
||||||
|
|
||||||
|
//文字列を受け取る
|
||||||
|
String str = scanner.nextLine();
|
||||||
|
//前後の空白除去
|
||||||
|
return str.strip();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//判定処理のメソッド
|
||||||
|
public static boolean isEmptyInput(String str) {
|
||||||
|
|
||||||
|
|
||||||
|
//空文字判定
|
||||||
|
if(str.isBlank()) {
|
||||||
|
System.out.println("何も入力されていません");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//文字数超過判定のメソッド
|
||||||
|
public static boolean isTooLongInput(String str) {
|
||||||
|
|
||||||
|
//文字数を数える
|
||||||
|
int count = str.length();
|
||||||
|
|
||||||
|
//140字超過判定
|
||||||
|
if(count > 140) {
|
||||||
|
System.out.println("投稿文が長すぎます");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//ここからメイン
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
//画面に「いまなにしてる?」を表示する
|
//画面に「いまなにしてる?」を表示する
|
||||||
System.out.println("いまなにしてる?");
|
System.out.println("いまなにしてる?");
|
||||||
|
|
||||||
//標準入力
|
//文字を入力
|
||||||
String str = scanner.nextLine();
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
//文字列前後の空白を除去
|
//入力した文章を変数に保存
|
||||||
System.out.println(str.strip());
|
String str = inputString(scanner);
|
||||||
|
|
||||||
//文字数を数える
|
|
||||||
int count = str.length();
|
|
||||||
|
|
||||||
|
|
||||||
//0字だった場合
|
//0字だった場合
|
||||||
if(str.isBlank()){
|
if(isEmptyInput(str)){
|
||||||
System.out.println("何も入力されていません");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//140字以上だった場合
|
//140字以上だった場合
|
||||||
else if(count >= 140) {
|
else if(isTooLongInput(str)) {
|
||||||
System.out.println("投稿文が長すぎます");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,8 +78,9 @@ public class StringCheack_20261009福森 {
|
|||||||
//投稿完了する
|
//投稿完了する
|
||||||
System.out.println("↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓");
|
System.out.println("↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓");
|
||||||
|
|
||||||
//入力した文章を表示
|
//文字列前後の空白を除去した文章を表示
|
||||||
System.out.println(str);
|
System.out.println(str);
|
||||||
|
scanner.close();
|
||||||
|
|
||||||
//終了
|
//終了
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user