题目
Description
从键盘输入一段英文,将其中的英文单词分离出来:已知单词之间的分隔符包括空格,问号、句号(小数点)和分号。
Input
输入一行字符串 (字符不超过1000)
Output
将分割后的单词按行输出
Sample Input
There are apples; oranges and peaches on the table.
Sample Output
There
are
apples
oranges
and
peaches
on
the
table
代码块
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cn = new Scanner(System.in);
String str = cn.nextLine();
String regex = " |\\;|\\.";
String[] data = str.split(regex);
for (int i = 0; i < data.length; i++) {
if (data[i].equals(""))
continue;
System.out.println(data[i]);
}
}
}