Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2441fad379 | |||
| 214745d348 | |||
| 59bef3b34f | |||
| 6b94afd5c1 |
@@ -1,93 +0,0 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class StringCheack_20261009福森 {
|
||||
|
||||
|
||||
//標準入力から1行読み込み、前後の空白を除去する処理のメソッド
|
||||
public static String inputString(Scanner scanner) {
|
||||
|
||||
//文字列を受け取る
|
||||
String str = scanner.nextLine();
|
||||
//前後の空白除去
|
||||
return str.strip();
|
||||
}
|
||||
|
||||
|
||||
//判定処理のメソッド
|
||||
public static boolean isEmptyInput(String str) {
|
||||
|
||||
|
||||
//空文字判定
|
||||
if(str.isBlank()) {
|
||||
System.out.println("何も入力されていません");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//文字数超過判定のメソッド
|
||||
public static boolean isTooLongInput(String str) {
|
||||
|
||||
//文字数を数える
|
||||
int count = str.length();
|
||||
|
||||
//140字超過判定
|
||||
if(count > 140) {
|
||||
System.out.println("投稿文が長すぎます");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//ここからメイン
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
while(true) {
|
||||
//画面に「いまなにしてる?」を表示する
|
||||
System.out.println("いまなにしてる?");
|
||||
|
||||
//文字を入力
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
//入力した文章を変数に保存
|
||||
String str = inputString(scanner);
|
||||
|
||||
|
||||
//0字だった場合
|
||||
if(isEmptyInput(str)){
|
||||
continue;
|
||||
}
|
||||
|
||||
//140字以上だった場合
|
||||
else if(isTooLongInput(str)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
else {
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
//投稿完了する
|
||||
System.out.println("↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓");
|
||||
|
||||
//文字列前後の空白を除去した文章を表示
|
||||
System.out.println(str);
|
||||
scanner.close();
|
||||
|
||||
//終了
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
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() {
|
||||
|
||||
|
||||
|
||||
}
|
||||
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() {
|
||||
|
||||
|
||||
|
||||
}
|
||||
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,66 +0,0 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class StringCheck_20261007福森 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
//画面に「いまなにしてる?」を表示する
|
||||
args = new String [4];
|
||||
|
||||
args[0] = "いまなにしてる?";
|
||||
args[1] = "何も入力されていません";
|
||||
args[2] = "投稿文が長すぎます";
|
||||
args[3] = "↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓";
|
||||
System.out.println(args[0]);
|
||||
|
||||
//文字列を入力させる
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String str = sc.next();
|
||||
|
||||
String text = str;
|
||||
|
||||
//文字数を数える
|
||||
int count = text.length();
|
||||
System.out.println(count);
|
||||
//空文字判定:str の文字数が 0 かどうか
|
||||
boolean num;
|
||||
int nums = count;
|
||||
|
||||
num = (nums == 0);
|
||||
System.out.println(num);
|
||||
|
||||
//文字数超過判定:str の文字数が 140 を超えるかどうか
|
||||
boolean num2;
|
||||
int nums2 = count;
|
||||
|
||||
num2 = (nums2 >= 140);
|
||||
System.out.println(num2);
|
||||
|
||||
//「残り入力可能文字数(140 - 文字数)」
|
||||
int rest;
|
||||
rest = 140 - count;
|
||||
System.out.println(rest);
|
||||
|
||||
//投稿完了
|
||||
System.out.println(args[3]);
|
||||
System.out.println(str);
|
||||
|
||||
//ここから
|
||||
System.out.println("いまなにしてる?");
|
||||
|
||||
for (int i = 0 ; i < 4; i++) {
|
||||
System.out.println("今は" + i + "です");
|
||||
|
||||
if (i == 2) {
|
||||
System.out.println("for文を抜けます");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user