1203: 单词分隔

来源:互联网 发布:人工智能意识 编辑:程序博客网 时间:2024/06/14 20:39

题目

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]);        }    }}
阅读全文
0 0