Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a8166141fe | |||
| 4ef56d8e05 | |||
| 1d0a61c9f9 | |||
| 6ae5b150d0 |
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
38
StringCheck20261007 石川.java
Normal file
38
StringCheck20261007 石川.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
47
StringCheck20261008_ishikawa.java
Normal file
47
StringCheck20261008_ishikawa.java
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
48
StringCheck_1009_ishikawa.java
Normal file
48
StringCheck_1009_ishikawa.java
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
73
StringCheck_20261013_ishikawa.java
Normal file
73
StringCheck_20261013_ishikawa.java
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
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