Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8ad1c0c686 | |||
| 4bfedad1b4 | |||
| cf94666c45 | |||
| 46e25104c2 |
@@ -1,68 +0,0 @@
|
||||
|
||||
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() {
|
||||
|
||||
|
||||
|
||||
}
|
||||
76
StringCheck20061009_瓦.java
Normal file
76
StringCheck20061009_瓦.java
Normal file
@@ -0,0 +1,76 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class StringCheck {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
|
||||
|
||||
String[] main;
|
||||
|
||||
main = new String[4];
|
||||
|
||||
main[0] = "いまなにしてる?";
|
||||
main[1] = "何も入力されていません";
|
||||
main[2] = "投稿文が長すぎます";
|
||||
main[3] = "↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓";
|
||||
|
||||
|
||||
|
||||
|
||||
System.out.println(main[0]);
|
||||
|
||||
System.out.println("");
|
||||
|
||||
while (true) {
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
String str = scanner.nextLine();
|
||||
str = str.replace(" ","").replace(" ","");
|
||||
|
||||
|
||||
|
||||
System.out.println("");
|
||||
|
||||
System.out.println("");
|
||||
|
||||
int length = str.length();
|
||||
|
||||
boolean isEmpty = length == 0;
|
||||
|
||||
boolean isTooLong = length >= 140;
|
||||
|
||||
int remaining = 140 - length;
|
||||
System.out.println("残りの文字数" + remaining);
|
||||
|
||||
|
||||
if (isEmpty) {
|
||||
System.out.println("何も入力されていません");
|
||||
continue;
|
||||
}
|
||||
|
||||
else if(isTooLong) {
|
||||
System.out.println("投稿文が長すぎます");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
System.out.println("");
|
||||
|
||||
System.out.println(main[3]);
|
||||
|
||||
System.out.println(str);
|
||||
|
||||
|
||||
|
||||
scanner.close();
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
82
StringCheck20261008_瓦.java
Normal file
82
StringCheck20261008_瓦.java
Normal file
@@ -0,0 +1,82 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class StringCheck {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
|
||||
|
||||
String[] main;
|
||||
|
||||
main = new String[4];
|
||||
|
||||
main[0] = "いまなにしてる?";
|
||||
main[1] = "何も入力されていません";
|
||||
main[2] = "投稿文が長すぎます";
|
||||
main[3] = "↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓";
|
||||
|
||||
for (String text : main) {
|
||||
System.out.println(text);
|
||||
}
|
||||
|
||||
|
||||
|
||||
System.out.println(main[0]);
|
||||
|
||||
System.out.println("");
|
||||
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
String str = scanner.nextLine();
|
||||
str = str.replace(" ","").replace(" ","");
|
||||
|
||||
while (true) {
|
||||
|
||||
System.out.println("");
|
||||
|
||||
System.out.println("");
|
||||
|
||||
|
||||
|
||||
int length = str.length();
|
||||
|
||||
boolean isEmpty = length == 0;
|
||||
System.out.println("0文字かどうか: " + isEmpty);
|
||||
|
||||
boolean inWithinLimit = length <= 140;
|
||||
System.out.println("140文字以下か?: " + inWithinLimit);
|
||||
|
||||
int remaining = 140 - length;
|
||||
System.out.println("残りの文字数" + remaining);
|
||||
|
||||
|
||||
if (isEmpty == true) {
|
||||
System.out.println("何も入力されていません");
|
||||
continue;
|
||||
}
|
||||
|
||||
else if(inWithinLimit = true) {
|
||||
System.out.println("投稿文が長すぎます");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
System.out.println("");
|
||||
|
||||
System.out.println(main[3]);
|
||||
|
||||
System.out.println(str);
|
||||
|
||||
|
||||
|
||||
scanner.close();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
|
||||
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,75 +0,0 @@
|
||||
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() {
|
||||
|
||||
|
||||
|
||||
}
|
||||
89
StringCheck20261013_瓦.java
Normal file
89
StringCheck20261013_瓦.java
Normal file
@@ -0,0 +1,89 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class StringCheck {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
//String型配列mainを宣言
|
||||
String[] main;
|
||||
|
||||
//配列に文字を代入していく
|
||||
main = new String[4];
|
||||
|
||||
main[0] = "いまなにしてる?";
|
||||
main[1] = "何も入力されていません";
|
||||
main[2] = "投稿文が長すぎます";
|
||||
main[3] = "↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓";
|
||||
|
||||
//ループ始まり
|
||||
while (true) {
|
||||
|
||||
|
||||
//今なにしてる?と表示する
|
||||
System.out.println(main[0]);
|
||||
|
||||
//String型の文字列 strを宣言
|
||||
String str;
|
||||
|
||||
//Scannerで読み込んだものをstrに代入
|
||||
str = inputString();
|
||||
|
||||
//文字の長さ判定
|
||||
int length = str.length();
|
||||
|
||||
//0文字の場合は「何も入力されていません」
|
||||
if (isEmptyInput(str)) {
|
||||
System.out.println(main[1]);
|
||||
continue;
|
||||
|
||||
//140文字を超えている場合は「投稿文が長すぎます」
|
||||
} else if (isTooLongInput(str)) {
|
||||
System.out.println(main[2]);
|
||||
continue;
|
||||
}
|
||||
|
||||
//残りの文字数を計算
|
||||
int remaining = 140 - length;
|
||||
System.out.println("残りの文字数" + remaining);
|
||||
|
||||
|
||||
//空白→投稿されました→文言出力
|
||||
System.out.println("");
|
||||
|
||||
System.out.println(main[3]);
|
||||
|
||||
System.out.println(str);
|
||||
|
||||
|
||||
//ループから抜ける
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
//文字を読み込んで空白を削除
|
||||
public static String inputString() {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
String str = scanner.nextLine();
|
||||
|
||||
return str.replace(" ", "").replace(" ", "");
|
||||
}
|
||||
//strの文字数は0文字か?
|
||||
public static boolean isEmptyInput(String str) {
|
||||
return str.length() == 0;
|
||||
|
||||
}
|
||||
//strの文字数は140文字以下か?
|
||||
public static boolean isTooLongInput(String str) {
|
||||
return str.length() >= 141;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
25
stringcheck20261007_瓦.java
Normal file
25
stringcheck20261007_瓦.java
Normal file
@@ -0,0 +1,25 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class stringcheck {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
String[] main;
|
||||
|
||||
main = new String[4];
|
||||
|
||||
main[0] = "いまなにしてる?";
|
||||
main[1] = "何も入力されていません";
|
||||
main[2] = "投稿文が長すぎます";
|
||||
main[3] = "↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓";
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
String line = scanner.nextLine();
|
||||
System.out.println(line);
|
||||
|
||||
scanner.close();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user