Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2441fad379 | |||
| 214745d348 | |||
| 59bef3b34f | |||
| 6b94afd5c1 |
68
StringCheck.java
Normal file
68
StringCheck.java
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
|
||||||
|
public class StringCheck {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
|
String[] name = {"いまなにしてる?", "何も入力されていません", "投稿文が長すぎます","↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓"};
|
||||||
|
|
||||||
|
String str;
|
||||||
|
|
||||||
|
str = (" gagaga" );
|
||||||
|
String stripped = str.strip();
|
||||||
|
//テスト
|
||||||
|
/*for (String stra : name ) {
|
||||||
|
System.out.println(stra);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
|
||||||
|
System.out.println(name[0]);
|
||||||
|
|
||||||
|
if (stripped.length() == 0) {
|
||||||
|
|
||||||
|
System.out.println(name[1]);
|
||||||
|
|
||||||
|
} else if (stripped.length() > 140) {
|
||||||
|
|
||||||
|
System.out.println(name[2]);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
System.out.println(stripped);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}}
|
||||||
|
System.out.println(" ");
|
||||||
|
|
||||||
|
System.out.println(name[3]);
|
||||||
|
|
||||||
|
System.out.println(stripped);
|
||||||
|
|
||||||
|
System.out.println(140 - stripped.length());
|
||||||
|
|
||||||
|
//0を超える文字数
|
||||||
|
System.out.println(0 <= stripped.length());
|
||||||
|
|
||||||
|
//140文字未満
|
||||||
|
System.out.println(stripped.length() <= 140);
|
||||||
|
}
|
||||||
|
|
||||||
|
//空白除去
|
||||||
|
public static String inputStrng(String str) {
|
||||||
|
String stripped;
|
||||||
|
return stripped = str.strip();
|
||||||
|
}
|
||||||
|
|
||||||
|
//空文字判定
|
||||||
|
//public static String isEmptyInput() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//文字数超過判定
|
||||||
|
//public static String isTooLongInput() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
package mission;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class StringCheck {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
|
||||||
//段階1
|
|
||||||
String[] a;
|
|
||||||
a = new String[4];
|
|
||||||
a[0] = "いまなにしてる?";
|
|
||||||
a[1] = "何も入力されていません";
|
|
||||||
a[2] = "投稿文が長すぎます";
|
|
||||||
a[3] = "↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓";
|
|
||||||
|
|
||||||
//段階2
|
|
||||||
Scanner sc = new Scanner(System.in);
|
|
||||||
String str = sc.nextLine();
|
|
||||||
System.out.println(str.trim());
|
|
||||||
|
|
||||||
//段階3
|
|
||||||
boolean b1 = str.length() == 0;
|
|
||||||
boolean b2= str.length() > 140;
|
|
||||||
|
|
||||||
System.out.println(b1);
|
|
||||||
System.out.println(b2);
|
|
||||||
|
|
||||||
int n = 140 - str.length();
|
|
||||||
System.out.println(n);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
package mission;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class StringCheck {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
|
||||||
String[] a;
|
|
||||||
a = new String[4];
|
|
||||||
a[0] = "いまなにしてる?";
|
|
||||||
a[1] = "何も入力されていません";
|
|
||||||
a[2] = "投稿文が長すぎます";
|
|
||||||
a[3] = "↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓";
|
|
||||||
|
|
||||||
Scanner sc = new Scanner(System.in);
|
|
||||||
String str;
|
|
||||||
while(true) {
|
|
||||||
System.out.println(a[0]);
|
|
||||||
str = sc.nextLine().strip();
|
|
||||||
System.out.println(str);
|
|
||||||
|
|
||||||
boolean b1 = str.length() == 0;
|
|
||||||
boolean b2 = str.length() > 140;
|
|
||||||
int n = 140 - str.length();
|
|
||||||
|
|
||||||
if(b1) {
|
|
||||||
System.out.println(a[1]);
|
|
||||||
continue;
|
|
||||||
}else if(b2) {
|
|
||||||
System.out.println(a[2]);
|
|
||||||
continue;
|
|
||||||
}else {
|
|
||||||
System.out.println(b1);
|
|
||||||
System.out.println(b2);
|
|
||||||
System.out.println(n);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.println();
|
|
||||||
System.out.println(a[3]);
|
|
||||||
System.out.println(str);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
68
StringCheck20261009_平山.java
Normal file
68
StringCheck20261009_平山.java
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
|
||||||
|
public class StringCheck {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
|
String[] name = {"いまなにしてる?", "何も入力されていません", "投稿文が長すぎます","↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓"};
|
||||||
|
|
||||||
|
String str;
|
||||||
|
|
||||||
|
str = (" gagaga" );
|
||||||
|
String stripped = str.strip();
|
||||||
|
//テスト
|
||||||
|
/*for (String stra : name ) {
|
||||||
|
System.out.println(stra);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
|
||||||
|
System.out.println(name[0]);
|
||||||
|
|
||||||
|
if (stripped.length() == 0) {
|
||||||
|
|
||||||
|
System.out.println(name[1]);
|
||||||
|
|
||||||
|
} else if (stripped.length() > 140) {
|
||||||
|
|
||||||
|
System.out.println(name[2]);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
System.out.println(stripped);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}}
|
||||||
|
System.out.println(" ");
|
||||||
|
|
||||||
|
System.out.println(name[3]);
|
||||||
|
|
||||||
|
System.out.println(stripped);
|
||||||
|
|
||||||
|
System.out.println(140 - stripped.length());
|
||||||
|
|
||||||
|
//0を超える文字数
|
||||||
|
System.out.println(0 <= stripped.length());
|
||||||
|
|
||||||
|
//140文字未満
|
||||||
|
System.out.println(stripped.length() <= 140);
|
||||||
|
}
|
||||||
|
|
||||||
|
//空白除去
|
||||||
|
public static String inputStrng(String str) {
|
||||||
|
String stripped;
|
||||||
|
return stripped = str.strip();
|
||||||
|
}
|
||||||
|
|
||||||
|
//空文字判定
|
||||||
|
//public static String isEmptyInput() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//文字数超過判定
|
||||||
|
//public static String isTooLongInput() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
75
StringCheck20261013_平山.java
Normal file
75
StringCheck20261013_平山.java
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class StringCheck {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
|
String[] name = {"いまなにしてる?", "何も入力されていません", "投稿文が長すぎます","↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓"};
|
||||||
|
|
||||||
|
String str;
|
||||||
|
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
|
||||||
|
System.out.println(name[0]);
|
||||||
|
str = inputString();
|
||||||
|
|
||||||
|
if (str.length() == 0) {
|
||||||
|
|
||||||
|
System.out.println(name[1]);
|
||||||
|
continue;
|
||||||
|
|
||||||
|
} else if (str.length() > 140) {
|
||||||
|
|
||||||
|
System.out.println(name[2]);
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
System.out.println(str);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}}
|
||||||
|
System.out.println(" ");
|
||||||
|
|
||||||
|
System.out.println(name[3]);
|
||||||
|
|
||||||
|
System.out.println(str);
|
||||||
|
|
||||||
|
System.out.println(140 - str.length());
|
||||||
|
|
||||||
|
//0を超える文字数
|
||||||
|
System.out.println(0 <= str.length());
|
||||||
|
|
||||||
|
//140文字未満
|
||||||
|
System.out.println(str.length() <= 140);
|
||||||
|
}
|
||||||
|
|
||||||
|
//空白除去
|
||||||
|
public static String inputString() {
|
||||||
|
//標準入力を読み込む準備をする
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
//一行分の文字列を読み込む
|
||||||
|
String str = sc.nextLine();
|
||||||
|
//読み込んだ文字列の前後にある空白を取り除く
|
||||||
|
return str.strip();
|
||||||
|
}
|
||||||
|
|
||||||
|
//空文字判定
|
||||||
|
public static boolean isEmptyInput(String str) {
|
||||||
|
|
||||||
|
if (str.length() == 0) {
|
||||||
|
return ;
|
||||||
|
System.out.println(name[1]);
|
||||||
|
continue;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//文字数超過判定
|
||||||
|
//public static String isTooLongInput() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package misstion2;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class StringCheck {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
|
||||||
String[] a;
|
|
||||||
a = new String[4];
|
|
||||||
a[0] = "いまなにしてる?";
|
|
||||||
a[1] = "何も入力されていません";
|
|
||||||
a[2] = "投稿文が長すぎます";
|
|
||||||
a[3] = "↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓";
|
|
||||||
|
|
||||||
Scanner sc = new Scanner(System.in);
|
|
||||||
String str;
|
|
||||||
while(true) {
|
|
||||||
System.out.println(a[0]);
|
|
||||||
str = sc.nextLine().strip();
|
|
||||||
System.out.println(str);
|
|
||||||
|
|
||||||
boolean b1 = str.length() == 0;
|
|
||||||
boolean b2 = str.length() > 140;
|
|
||||||
int n = 140 - str.length();
|
|
||||||
|
|
||||||
if(b1) {
|
|
||||||
System.out.println(a[1]);
|
|
||||||
continue;
|
|
||||||
}else if(b2) {
|
|
||||||
System.out.println(a[2]);
|
|
||||||
continue;
|
|
||||||
}else {
|
|
||||||
System.out.println(b1);
|
|
||||||
System.out.println(b2);
|
|
||||||
System.out.println(n);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.println();
|
|
||||||
System.out.println(a[3]);
|
|
||||||
System.out.println(str);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
49
StringCheck_20261007_平山.java
Normal file
49
StringCheck_20261007_平山.java
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
|
||||||
|
public class StringCheck {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
|
String[] name = {"いまなにしてる?", "何も入力されていません", "投稿文が長すぎます","↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓"};
|
||||||
|
|
||||||
|
String str;
|
||||||
|
str = ("こんにちはこんばんはこんにちはこんばんはこんにちはこんばんはこんにちはこんばんはこんにちはこんばんはこんにちはこんばんはこんにちはこんばんはこんにちはこんばんはこんにちはこんばんはこんにちはこんばんはこんにちはこんばんはこんにちはこんばんはこんにちはこんばんはこんにちはこんばんはこんにちはこんばんは" );
|
||||||
|
|
||||||
|
//テスト
|
||||||
|
/*for (String stra : name ) {
|
||||||
|
System.out.println(stra);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
|
||||||
|
System.out.println(name[0]);
|
||||||
|
|
||||||
|
if (str.length() == 0) {
|
||||||
|
System.out.println(name[1]);
|
||||||
|
} else if (str.length() > 141) {
|
||||||
|
System.out.println(name[2]);
|
||||||
|
} else {
|
||||||
|
System.out.println(str);
|
||||||
|
|
||||||
|
System.out.println(" ");
|
||||||
|
|
||||||
|
System.out.println(name[3]);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(140 - str.length());
|
||||||
|
|
||||||
|
//0を超える文字数
|
||||||
|
System.out.println(0 == str.length());
|
||||||
|
|
||||||
|
//140文字未満
|
||||||
|
System.out.println(str.length() < 141);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
package misstion2;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class StringCheck {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
|
||||||
String[] text;
|
|
||||||
text = new String[4];
|
|
||||||
text[0] = "いまなにしてる?";
|
|
||||||
text[1] = "何も入力されていません";
|
|
||||||
text[2] = "投稿文が長すぎます";
|
|
||||||
text[3] = "↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓";
|
|
||||||
|
|
||||||
String str;
|
|
||||||
int l = 140;//文字数の上限値
|
|
||||||
|
|
||||||
while(true) {
|
|
||||||
System.out.println(text[0]);
|
|
||||||
str = inputString();//標準入力を受け取る
|
|
||||||
System.out.println(str);//上を出力
|
|
||||||
|
|
||||||
boolean b1 = isEmptyInput(str);//入力された文字数が0の時
|
|
||||||
boolean b2 = isTooLongInput(str, l);//上限値を超えた時
|
|
||||||
int n = l - str.length();//残りの入力可能文字数の算出
|
|
||||||
|
|
||||||
//入力された文字数に応じて配列[text]を出力
|
|
||||||
if(b1) {
|
|
||||||
System.out.println(text[1]);
|
|
||||||
continue;
|
|
||||||
}else if(b2) {
|
|
||||||
System.out.println(text[2]);
|
|
||||||
continue;
|
|
||||||
}else {
|
|
||||||
System.out.println(b1);
|
|
||||||
System.out.println(b2);
|
|
||||||
System.out.println(n);//残りの入力可能文字数を出力
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.println();
|
|
||||||
System.out.println(text[3]);
|
|
||||||
System.out.println(str);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//標準入力受け取りのメソッド
|
|
||||||
public static String inputString() {
|
|
||||||
Scanner sc = new Scanner(System.in);
|
|
||||||
String str;
|
|
||||||
str = sc.nextLine().strip();
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
//文字数0のメソッド
|
|
||||||
public static boolean isEmptyInput(String str) {
|
|
||||||
boolean b1 = str.length() == 0;
|
|
||||||
return b1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//文字数超過のメソッド
|
|
||||||
public static boolean isTooLongInput(String str) {
|
|
||||||
boolean b2 = str.length() > 140;
|
|
||||||
return b2;
|
|
||||||
}
|
|
||||||
|
|
||||||
//追加したメソッド
|
|
||||||
public static boolean isTooLongInput(String str, int l) {
|
|
||||||
boolean b2 = str.length() > l;
|
|
||||||
return b2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user