Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c61a21e301 | |||
| 66b2c6fa05 | |||
| 9a78905b5f | |||
| e9bc08ff77 | |||
| 8d80534623 | |||
| 4d5fb38d67 | |||
| 63c41c675a | |||
| eda22e495e | |||
| 7c155854d4 | |||
| 9f5b2fe62c | |||
| e73be5ce5a | |||
| 8c0c4fa5a6 | |||
| c58ea498a6 | |||
| a05245bbf8 | |||
| 9cbc270869 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -24,4 +24,3 @@
|
|||||||
hs_err_pid*
|
hs_err_pid*
|
||||||
replay_pid*
|
replay_pid*
|
||||||
|
|
||||||
/.metadata/
|
|
||||||
|
|||||||
44
PJ/src/StringCheck.java
Normal file
44
PJ/src/StringCheck.java
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class StringCheck {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String[] message = new String[4];
|
||||||
|
message[0] = "いまなにしてる?";
|
||||||
|
message[1] = "何も入力されていません";
|
||||||
|
message[2] = "投稿文が長すぎます";
|
||||||
|
message[3] = "↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓";
|
||||||
|
|
||||||
|
//System.out.println(message[2]);
|
||||||
|
|
||||||
|
// for (int i = 0; i < message.length; i++) {
|
||||||
|
// System.out.println(message[i]);
|
||||||
|
// }
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
System.out.println(message[0]);
|
||||||
|
String str = scanner.nextLine().strip();
|
||||||
|
|
||||||
|
int strlen = str.length();
|
||||||
|
boolean isEmpty = strlen == 0;
|
||||||
|
boolean isOver = ((140 - strlen) < 0);
|
||||||
|
|
||||||
|
if (isEmpty == true) {
|
||||||
|
System.out.println(message[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isOver == true) {
|
||||||
|
System.out.println(message[2]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
System.out.println("");
|
||||||
|
System.out.println(message[3]);
|
||||||
|
System.out.println(str);
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -42,6 +42,14 @@ public class StringCheck {
|
|||||||
"↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓"
|
"↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// 2日目 段階1:標準入力を読み取る準備をする
|
||||||
|
// ============================================================
|
||||||
|
// Scanner は、キーボードからの入力(標準入力)を読み取るためのクラス。
|
||||||
|
// ループの中で毎回新しく作るのではなく、ループの外で1回だけ用意して
|
||||||
|
// 使い回す。
|
||||||
|
//Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
// 投稿内容(前後の空白を除去したあとの文字列)を保持する変数。
|
// 投稿内容(前後の空白を除去したあとの文字列)を保持する変数。
|
||||||
// while文を抜けたあとでも使うので、while文の外で宣言しておく。
|
// while文を抜けたあとでも使うので、while文の外で宣言しておく。
|
||||||
String str = "";
|
String str = "";
|
||||||
@@ -59,6 +67,20 @@ public class StringCheck {
|
|||||||
System.out.println(messages[0]);
|
System.out.println(messages[0]);
|
||||||
|
|
||||||
str = inputString();
|
str = inputString();
|
||||||
|
// ---- 1日目 段階2:標準入力の読み込みと空白除去 ----
|
||||||
|
// キーボードから1行分の文字列を読み取る。
|
||||||
|
//String line = scanner.nextLine();
|
||||||
|
// 読み取った文字列の前後にある空白文字(半角スペース・全角スペース
|
||||||
|
// など)を取り除き、str に格納する。
|
||||||
|
//str = line.strip();
|
||||||
|
|
||||||
|
// ---- 1日目 段階3:比較演算子で真偽値を求める ----
|
||||||
|
// 1日目の時点ではif文がまだ使えなかったため、この2つの真偽値は
|
||||||
|
// 画面に表示して目視確認するだけだった。
|
||||||
|
// 2日目からは、この真偽値をそのままif文の条件として使う。
|
||||||
|
//boolean isEmpty = (str.length() == 0);
|
||||||
|
//boolean isTooLong = (str.length() > 140);
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// 2日目 段階2:if文による検証ロジック
|
// 2日目 段階2:if文による検証ロジック
|
||||||
// ============================================================
|
// ============================================================
|
||||||
@@ -90,24 +112,28 @@ public class StringCheck {
|
|||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println(messages[3]);
|
System.out.println(messages[3]);
|
||||||
System.out.println(str);
|
System.out.println(str);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String inputString() {
|
public static String inputString() {
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
return scanner.nextLine().strip();
|
// ---- 1日目 段階2:標準入力の読み込みと空白除去 ----
|
||||||
|
// キーボードから1行分の文字列を読み取る。
|
||||||
|
String line = scanner.nextLine();
|
||||||
|
// 読み取った文字列の前後にある空白文字(半角スペース・全角スペース
|
||||||
|
// など)を取り除き、str に格納する。
|
||||||
|
return line.strip();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isEmptyInput(String str) {
|
public static boolean isEmptyInput(String str) {
|
||||||
boolean isEmpty = (str.length() == 0);
|
boolean isEmpty = (str.length() == 0);
|
||||||
return isEmpty;
|
return isEmpty;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isTooLongInput(String str) {
|
public static boolean isTooLongInput(String str) {
|
||||||
boolean isTooLong = (str.length() > 140);
|
boolean isTooLong = (str.length() > 140);
|
||||||
return isTooLong;
|
return isTooLong;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 見直しできました
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//段階3の見直しは完了済みです!
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class StringCheck {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
// 初期化・宣言
|
|
||||||
String[] classNames = {
|
|
||||||
"いまなにしてる?",
|
|
||||||
"何も入力されていません",
|
|
||||||
"投稿文が長すぎます",
|
|
||||||
"↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓",
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
//標準入力から1行分の文字列を読み込む
|
|
||||||
Scanner scan = new Scanner(System.in);
|
|
||||||
|
|
||||||
String str = "";
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
|
|
||||||
System.out.println(classNames[0]);
|
|
||||||
str = scan.nextLine();
|
|
||||||
|
|
||||||
// 前後の空白を除去した文字列
|
|
||||||
String trimmed = str.strip();
|
|
||||||
|
|
||||||
// 文字列の長さを取得
|
|
||||||
int length = trimmed.length();
|
|
||||||
|
|
||||||
// 空字判定(空白だけも含む)
|
|
||||||
boolean isEmpty = (length == 0);
|
|
||||||
|
|
||||||
// 文字数超過判定
|
|
||||||
boolean isOverLimit = (length > 140);
|
|
||||||
|
|
||||||
// 残り入力可能文字数
|
|
||||||
int a = (140 - length);
|
|
||||||
|
|
||||||
// if文による検証ロジック
|
|
||||||
if (isEmpty) {
|
|
||||||
System.out.println(classNames[1]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (isOverLimit) {
|
|
||||||
System.out.println(classNames[2]);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
}
|
|
||||||
System.out.println();
|
|
||||||
System.out.println(classNames[3]);
|
|
||||||
//読み込んだ文字列の前後にある空白文字を除去
|
|
||||||
System.out.println(str.strip());
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user