统计单词出现的次数。
2016-10-30 20:01
127 查看
Package com.company;
Import java.util.*;
Public class Mian{
Public static void main(String[] args){
System.out.println(“请输入一段英文”);
Scanner sc=new Scanner(System.in);
String strPara =sc.nextLine();
String[] strArray =strPara.split(“ ”);
Map<String,Integer> mapWords =new HashMap<String,Integer>();
For(String str :strArray)
{
If(!mapWords.containsKey(str))
{
mapWords.put(str,1);
}
else
{
Integer iCount=mapWords.get(str);
iCount++;
mapWords.put(str,iCount);
}
}
For(Map.Entry<String,Integer>me:mapWords.entrySet())
{
String strKey=me.getKey();
Integer iCount=me.getValue();
System.out.println(strKey+”出现了”+iCount+”次”);
}
}
}
Import java.util.*;
Public class Mian{
Public static void main(String[] args){
System.out.println(“请输入一段英文”);
Scanner sc=new Scanner(System.in);
String strPara =sc.nextLine();
String[] strArray =strPara.split(“ ”);
Map<String,Integer> mapWords =new HashMap<String,Integer>();
For(String str :strArray)
{
If(!mapWords.containsKey(str))
{
mapWords.put(str,1);
}
else
{
Integer iCount=mapWords.get(str);
iCount++;
mapWords.put(str,iCount);
}
}
For(Map.Entry<String,Integer>me:mapWords.entrySet())
{
String strKey=me.getKey();
Integer iCount=me.getValue();
System.out.println(strKey+”出现了”+iCount+”次”);
}
}
}
相关文章推荐
- Linux命令经典面试题:统计文件中出现次数最多的前10个单词
- java小算法—统计句子中每个单词出现的次数
- 练习2-4:编一个程序统计文件中特定单词出现的次数(要求使用string类的运算符==来查找单词)
- 第0004道练习题_Python统计文本里单词出现次数
- 金山2014秋招笔试题——统计单词在一篇文章中出现的次数和位置
- 黑马程序员——统计文件中每个英文单词出现的次数
- 高效统计从控制台输入的英文单词出现的次数,按照从高到低进行统计显示
- 统计某个单词出现的次数
- 统计单词出现的次数
- python 统计单词出现次数
- Java统计一篇英文单词出现次数
- Linux作业(三)-shell统计某文章中出现频率最高的N个单词并排序输出出现次数
- 统计单词出现的最多次数(Trie树)
- java-统计一段句子中各单词出现的次数
- 练习2-4:编一个程序统计文件中特定单词出现的次数(要求使用string类的运算符==来查找单词) .
- JavaScript中模拟java的map键值统计一段英文中各个单词出现的次数
- 统计文件中出现次数最多的前10个单词
- Hadoop 统计文件中某个单词出现的次数
- 统计出现次数最多的单词
- C++从一个文件中统计所有出现过的单词,并按次数从大到小输出