20261013
This commit is contained in:
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