マイクロ:
入力:彼はいい人です。
所望の出力:{「彼は」、「である」、「」、「良い」、「人」}
プログラムの出力:{ "彼は"、 "である"、 ""、 "良い"、」」、 "人"}
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String s = scan.nextLine();
String[] ace = s.trim().split("[\\s+!,?._'@]");
scan.close();
System.out.println(ace.length);
for(String c : ace)
System.out.println(c);
}
}
ここで初めて求めています。次回の必要ポインタ
Mureinik:
スペースとカンマ - あなたは「良い」と「人」との間に2つの区切り文字の配列を有します。あなたは同じ区切り文字として複数の連続する区切り文字を許可するように正規表現を微調整することができます:
String[] ace = s.trim().split("[\\s+!,?._'@]+");
// Here ------------------------------------^