java对于键盘输入的一段英文,请统计这段话中所含英文单词数并输出每个单词。 英文: Academic expert retrieval is a process of searching recognized researchers with high academic status and influence in a given scientific research field, relying on computer as a tool and using statistical knowledge, data mining and artificial intelligence technologies.代码
时间: 2023-05-18 15:06:29 浏览: 345
从键盘上输入一串英文字符(不含空格与其他字符),统计每个字符的数目,并输出字母及相应的数目。
以下是统计英文单词数并输出每个单词的 Java 代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入一段英文:");
String input = scanner.nextLine();
// 将输入字符串按空格分割成单词数组
String[] words = input.split("\\s+");
System.out.println("单词数:" + words.length);
System.out.println("每个单词:");
for (String word : words) {
System.out.println(word);
}
}
}
输入示例:
请输入一段英文:
Academic expert retrieval is a process of searching recognized researchers with high academic status and influence in a given scientific research field, relying on computer as a tool and using statistical knowledge, data mining and artificial intelligence technologies.
输出示例:
单词数:27
每个单词:
Academic
expert
retrieval
is
a
process
of
searching
recognized
researchers
with
high
academic
status
and
influence
in
a
given
scientific
research
field,
relying
on
computer
as
a
tool
and
using
statistical
knowledge,
data
mining
and
artificial
intelligence
technologies.
阅读全文