首页 > 其他 > 详细

第三次作业

时间:2016-03-16 13:54:17      阅读:193      评论:0      收藏:0      [点我收藏+]

第三次作业对我来说难度太大了,java刚学并不太会,借鉴了同学的代码测试运行。

源代码:

package ff;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Map.Entry;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class F { public static void main(String arg[])
{ Map<String,Integer> map=new HashMap<String,Integer>();
String content="Word is case insensitive, i.e. “file”, “FILE” and “File” are considered the same word."+
"If you weeped for the missing sunset,you would miss all the shining stars";
content=content.toLowerCase();
StringTokenizer token=new StringTokenizer(content);
while(token.hasMoreTokens())
{
String word=token.nextToken(", “”?.!:\"\"‘‘\n");
int count;
if(map.containsKey(word))
{
count=map.get(word);
map.put(word, count+1);
}
else
map.put(word, 1);
}
sort(map);
}

public static void sort(Map<String,Integer> map)
{
List<Map.Entry<String, Integer>> infoIds = new ArrayList<Map.Entry<String, Integer>>(map.entrySet());
for (int i = 0; i < infoIds.size(); i++)
{
Entry<String, Integer> id = infoIds.get(i);
if(id.getKey().length()>=4)
{System.out.println(id.getKey()+":"+id.getValue());}
}
}

}

运行结果如下:

技术分享

技术分享

第三次作业

原文:http://www.cnblogs.com/yanrui666/p/5282984.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!