Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 04e544ae85 | |||
| 709e454380 | |||
| a85256b39d | |||
| 107e11a567 | |||
| d3086351dd | |||
| 040e0d8b48 | |||
| dc289e7821 | |||
| a8ba4e4098 | |||
| 0efa10e7df | |||
| 22920ecacb | |||
| c265cee178 | |||
| 061c8c36dc | |||
| aa08ab7f8e |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -24,3 +24,4 @@
|
|||||||
hs_err_pid*
|
hs_err_pid*
|
||||||
replay_pid*
|
replay_pid*
|
||||||
|
|
||||||
|
/.metadata/
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
60
StringCheck/src/StringCheck.java
Normal file
60
StringCheck/src/StringCheck.java
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -42,14 +42,6 @@ public class StringCheck {
|
|||||||
"↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓"
|
"↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓"
|
||||||
};
|
};
|
||||||
|
|
||||||
// ============================================================
|
|
||||||
// 2日目 段階1:標準入力を読み取る準備をする
|
|
||||||
// ============================================================
|
|
||||||
// Scanner は、キーボードからの入力(標準入力)を読み取るためのクラス。
|
|
||||||
// ループの中で毎回新しく作るのではなく、ループの外で1回だけ用意して
|
|
||||||
// 使い回す。
|
|
||||||
//Scanner scanner = new Scanner(System.in);
|
|
||||||
|
|
||||||
// 投稿内容(前後の空白を除去したあとの文字列)を保持する変数。
|
// 投稿内容(前後の空白を除去したあとの文字列)を保持する変数。
|
||||||
// while文を抜けたあとでも使うので、while文の外で宣言しておく。
|
// while文を抜けたあとでも使うので、while文の外で宣言しておく。
|
||||||
String str = "";
|
String str = "";
|
||||||
@@ -67,20 +59,6 @@ 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文による検証ロジック
|
||||||
// ============================================================
|
// ============================================================
|
||||||
@@ -112,28 +90,24 @@ 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);
|
||||||
// ---- 1日目 段階2:標準入力の読み込みと空白除去 ----
|
return scanner.nextLine().strip();
|
||||||
// キーボードから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の見直しは完了済みです!
|
|
||||||
Reference in New Issue
Block a user