packagejavaapplication15;publicclassJavaApplication15{publicstaticvoidmain(String[]args){Stringarticle="Sendersandreceiversareofcoursevitalincommunication.Inface-to-facec...
package javaapplication15;
public class JavaApplication15 {
public static void main(String[] args) {
String article = "Senders and receivers are of course vital in communication. In face-to-face communication the roles of the sender and receiver are not distinct as both parties communicate with each other, even if in very subtle ways such as through eye-contact (or lack of) and general body language. There are many other subtle ways that we communicate (perhaps even unintentionally) with others, for example the tone of our voice can give clues to our mood or emotional state, whilst hand signals or gestures can add to a spoken message.";
String regex = "[\\p{Punct}\\s]{1,}";
String s[] = article.split(regex);
System.out.println("单词总数:" + s.length);
int i, j, max = 1;
for (i = 0; i < s.length; i++) {
s[i] = s[i].toLowerCase();//所有大写转为小写
}
下面就要检测单词的重复次数并且输出重复最多的前五个单词(最好不要用map方法)
展开