Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c0de9c3f67 | |||
| 32a42fb773 | |||
| 9beb98be38 | |||
| fc72196f76 | |||
| caa6bbcb5e | |||
| cd7ef1f091 | |||
| 21b2a758c3 | |||
| 00fe79abda | |||
| 79c6053700 | |||
| 0e993bd39b | |||
| a0627f4c7f | |||
| 6c3504cc75 | |||
| caf26a9c4b |
@@ -1,70 +0,0 @@
|
||||
package day3;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
|
||||
public class StringCheck {
|
||||
public static void main(String[] args) {
|
||||
|
||||
String[] messages = {
|
||||
"いまなにしてる?",
|
||||
"何も入力されていません",
|
||||
"投稿文が長すぎます",
|
||||
"↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓"
|
||||
};
|
||||
|
||||
|
||||
|
||||
String str = "";
|
||||
|
||||
|
||||
while (true) {
|
||||
System.out.println(messages[0]);
|
||||
|
||||
|
||||
str = imputString();
|
||||
|
||||
// boolean isEmpty = (str.length() == 0);
|
||||
// boolean isTooLong = (str.length() > 140);
|
||||
|
||||
|
||||
if (isEmptyInput(str)) {
|
||||
System.out.println(messages[1]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isTooLongInput(str)) {
|
||||
System.out.println(messages[2]);
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
System.out.println(messages[3]);
|
||||
System.out.println(str);
|
||||
}
|
||||
|
||||
public static String imputString() {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
String line = scanner.nextLine();
|
||||
return line.strip();
|
||||
}
|
||||
|
||||
public static boolean isEmptyInput(String text) {
|
||||
return text.length() == 0;
|
||||
|
||||
}
|
||||
|
||||
public static boolean isTooLongInput(String text) {
|
||||
return isTooLongInput(text,140);
|
||||
|
||||
}
|
||||
|
||||
public static boolean isTooLongInput(String text,int limmit) {
|
||||
return text.length() > limmit;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
package stringCheck;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class StringCheck {
|
||||
public static void main(String[] args) {
|
||||
String[] comment = new String[4];
|
||||
comment[0] = "いまなにしてる?";
|
||||
comment[1] = "何も入力されていません";
|
||||
comment[2] = "投稿文が長すぎます";
|
||||
comment[3] = "\"↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓\"";
|
||||
|
||||
|
||||
|
||||
while (true) {
|
||||
System.out.println(comment[0]);
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
String text = scanner.nextLine();
|
||||
String str = text.strip();
|
||||
|
||||
|
||||
|
||||
if(str.length() == 0) {
|
||||
System.out.println("何も入力されていません");
|
||||
continue;
|
||||
}else if(str.length() > 140){
|
||||
System.out.println("投稿文が長すぎます");
|
||||
continue;
|
||||
}else {
|
||||
System.out.println("\n" + comment[3]);
|
||||
System.out.println(str);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package stringCheck;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class StringCheck4 {
|
||||
public static void main(String[] args) {
|
||||
String[] comment = new String[4];
|
||||
comment[0] = "いまなにしてる?";
|
||||
comment[1] = "何も入力されていません";
|
||||
comment[2] = "投稿文が長すぎます";
|
||||
comment[3] = "\"↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓\"";
|
||||
|
||||
String str;
|
||||
|
||||
|
||||
while (true) {
|
||||
System.out.println(comment[0]);
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
String text = scanner.nextLine();
|
||||
str = text.strip();
|
||||
|
||||
if(str.length() == 0) {
|
||||
System.out.println("何も入力されていません");
|
||||
continue;
|
||||
}else if(str.length() > 140){
|
||||
System.out.println("投稿文が長すぎます");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
System.out.println("\n" + comment[3]);
|
||||
System.out.println(str);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package stringCheck;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class StringCheck4_1 {
|
||||
public static void main(String[] args) {
|
||||
String[] comment = new String[4];
|
||||
comment[0] = "いまなにしてる?";
|
||||
comment[1] = "何も入力されていません";
|
||||
comment[2] = "投稿文が長すぎます";
|
||||
comment[3] = "\"↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓\"";
|
||||
|
||||
|
||||
|
||||
while (true) {
|
||||
System.out.println(comment[0]);
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
String text = scanner.nextLine();
|
||||
String str = text.strip();
|
||||
|
||||
if(str.length() == 0) {
|
||||
System.out.println("何も入力されていません");
|
||||
continue;
|
||||
}else if(str.length() > 140){
|
||||
System.out.println("投稿文が長すぎます");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
System.out.println("\n" + comment[3]);
|
||||
System.out.println(str);
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package stringCheck;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class StringCheck5 {
|
||||
public static void main(String[] args) {
|
||||
String[] comment = new String[4];
|
||||
comment[0] = "いまなにしてる?";
|
||||
comment[1] = "何も入力されていません";
|
||||
comment[2] = "投稿文が長すぎます";
|
||||
comment[3] = "\"↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓\"";
|
||||
|
||||
|
||||
|
||||
while (true) {
|
||||
System.out.println(comment[0]);
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
String text = scanner.nextLine();
|
||||
String str = text.strip();
|
||||
|
||||
|
||||
String result;
|
||||
|
||||
result =
|
||||
|
||||
if(str.length() == 0) {
|
||||
System.out.println("何も入力されていません");
|
||||
continue;
|
||||
}else if(str.length() > 140){
|
||||
System.out.println("投稿文が長すぎます");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
System.out.println("\n" + comment[3]);
|
||||
System.out.println(str);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package stringCheck;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class StringCheckRef {
|
||||
public static void main(String[] args) {
|
||||
String[] comment = new String[4];
|
||||
comment[0] = "いまなにしてる?";
|
||||
comment[1] = "何も入力されていません";
|
||||
comment[2] = "投稿文が長すぎます";
|
||||
comment[3] = "\"↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓\"";
|
||||
|
||||
|
||||
|
||||
while (true) {
|
||||
System.out.println(comment[0]);
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
String text = scanner.nextLine();
|
||||
String str = text.strip();
|
||||
|
||||
|
||||
|
||||
if((0<str.length()) && (str.length()<=140)){
|
||||
System.out.println("\n" + comment[3]);
|
||||
System.out.println(str);
|
||||
break;
|
||||
}else if(str.length() == 0) {
|
||||
System.out.println("何も入力されていません");
|
||||
continue;
|
||||
}else {
|
||||
System.out.println("投稿文が長すぎます");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
今回は「mainに残したままでよい」と判断いたします。
|
||||
理由としましては、詳細設計書の「10. 疑似コード」において投稿完了時の表示処理がmainメソッド内に書いてあるからです。
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>StringCheck</name>
|
||||
<name>javalesson1</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
@@ -22,7 +22,7 @@ import java.util.Scanner;
|
||||
* ・例外処理(try-catch)
|
||||
* ------------------------------------------------------------
|
||||
*/
|
||||
public class StringCheckSample {
|
||||
public class StringCheck {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -48,7 +48,7 @@ public class StringCheckSample {
|
||||
// Scanner は、キーボードからの入力(標準入力)を読み取るためのクラス。
|
||||
// ループの中で毎回新しく作るのではなく、ループの外で1回だけ用意して
|
||||
// 使い回す。
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
;
|
||||
|
||||
// 投稿内容(前後の空白を除去したあとの文字列)を保持する変数。
|
||||
// while文を抜けたあとでも使うので、while文の外で宣言しておく。
|
||||
@@ -62,28 +62,29 @@ public class StringCheckSample {
|
||||
// 作りにする。
|
||||
while (true) {
|
||||
|
||||
|
||||
// ---- 1日目 段階3:プロンプトの表示 ----
|
||||
// 配列の0番目に入れておいたプロンプト文言を表示する。
|
||||
System.out.println(messages[0]);
|
||||
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文による検証ロジック
|
||||
// ============================================================
|
||||
if (isEmpty) {
|
||||
if (isEmptyInput(str)) {
|
||||
// 何も入力されていない(または空白のみ入力された)場合
|
||||
System.out.println(messages[1]);
|
||||
// continue で、while文の先頭(プロンプト表示)に戻り、
|
||||
@@ -91,7 +92,7 @@ public class StringCheckSample {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isTooLong) {
|
||||
if (isTooLongInput(str)) {
|
||||
// 141文字以上入力された場合
|
||||
System.out.println(messages[2]);
|
||||
// continue で、while文の先頭に戻る。
|
||||
@@ -112,5 +113,20 @@ public class StringCheckSample {
|
||||
System.out.println(messages[3]);
|
||||
System.out.println(str);
|
||||
}
|
||||
public static String inputString() {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
String line = scanner.nextLine();
|
||||
String str;
|
||||
return str = line.strip();
|
||||
}
|
||||
public static boolean isEmptyInput(String str) {
|
||||
boolean isEmpty = (str.length() == 0);
|
||||
return isEmpty;
|
||||
}
|
||||
public static boolean isTooLongInput(String str) {
|
||||
boolean isTooLong = (str.length() > 140);
|
||||
return isTooLong;
|
||||
}
|
||||
//見直しできました。
|
||||
}
|
||||
|
||||
43
javalesson1/src/javalesson1/StringCheck.java
Normal file
43
javalesson1/src/javalesson1/StringCheck.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package javalesson1;
|
||||
import java.util.Scanner;
|
||||
|
||||
|
||||
public class StringCheck {
|
||||
public static void main(String[] args) {
|
||||
String[] classNames= new String[4];
|
||||
classNames[0]="いまなにしている?";
|
||||
classNames[1]="何も入力されていません";
|
||||
classNames[2]="投稿文が長すぎます";
|
||||
classNames[3]="↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓";
|
||||
while(true) {
|
||||
System.out.println(classNames[0]);
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
String text = scanner.nextLine();
|
||||
System.out.println();
|
||||
|
||||
|
||||
String str= text.trim();
|
||||
|
||||
System.out.println(str);
|
||||
int length=str.length();
|
||||
boolean boolean1=(length==0);
|
||||
boolean boolean2=(length> 140);
|
||||
System.out.println(boolean1);
|
||||
System.out.println(boolean2);
|
||||
System.out.println(140 - length);
|
||||
|
||||
if(length==0) {
|
||||
System.out.println(classNames[1]);
|
||||
|
||||
} else if(length> 140) {
|
||||
System.out.println(classNames[2]);
|
||||
|
||||
} else {
|
||||
System.out.println(str);
|
||||
System.out.println();
|
||||
System.out.println(classNames[3]);
|
||||
System.out.println(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user