关于文本的字符单词行数的统计

import java.util.HashMap;
import java.util.Map;
import java.io.*;
public class test{
private static String WORD = "0"; 
private static String CHAR= "1"; 
private static String SENTENCE = "2"; 
public static Map<String, Integer> getCount(String str) {
str = str.replace(".", "#"); 
str = str.replace("?", "#"); 
str = str.replace("!", "#"); 
int wordCount = str.split(" ").length; 
int wordCount = str.split("*").length; 
int sentenceCount = str.split("#").length; 
Map<String, Integer> map = new HashMap<String, Integer>();
map.put(WORD, wordCount); 
map.put(CHAR, CHARCount); 
map.put(SENTENCE, sentenceCount); 
return map;
}

public static void main(String[] args) throws NumberFormatException, IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String x=br.readLine();
Map<String, Integer> map = getCount(x);
System.out.println("单词数量: "+map.get(WORD));
System.out.println("字符数量: "+map.get(CHAR));
System.out.println("句子数量: " + map.get(SENTENCE));
}
}

个人耗时表

posted on 2017-03-27 17:46  xiaoyun1  阅读(136)  评论(0编辑  收藏  举报