github:https://github.com/zhonghongyao/WordSplit.git
switch (count){
case 1:String strSource[]=line.split(" ");
for (int i = 0; i < strArray.length; i++) {
for (int j = 0; j < strSource.length; j++) {
if(strArray[i].equals(strSource[j])){
arrCount[i]++;
}
}
}
default:String strAll[]=line.split(" ");
for (int i = 0; i <strAll.length ; i++) {
if(map.size()==0){
map.put(strAll[i],1);
continue;
}
int size=map.size();
boolean flag=false;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if(entry.getKey().equals(strAll[i])){
int temp=entry.getValue();
entry.setValue(++temp);
flag=true;
}
}
if(flag==false){
map.put(strAll[i],1);
}
}
break;
}
}
//输出
if(count==1){
for (int i = 0; i <strArray.length ; i++) {
System.out.print(strArray[i]+"-----数量:"+arrCount[i]+" ");
//柱形图
}
}else if(count==2){
Map<String,Integer>mapResult=MapSort.sortMapByValue(map);
for (Map.Entry<String, Integer> entry : mapResult.entrySet()) {
if(k==0){
break;
}else {
System.out.println("单词= " + entry.getKey() + " 数量= " + entry.getValue());
k--;
}
}
}else if(count==3){
Map<String,Integer>mapRe= MapSort.sortMapByValue(map);
writeFile(mapRe);
}
} catch (IOException e) {
e.printStackTrace();
}
}
本项目采用类思想分块处理,实现了软件工程的“高内聚,低耦合”思想
原文:https://www.cnblogs.com/zhonghongyao/p/10561974.html