1 Star 0 Fork 0

zhuyu1054988241/wordCount3

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Test-功能扩展.java 2.26 KB
一键复制 编辑 原始数据 按行查看 历史
zhuyu1054988241 提交于 2018-10-19 11:10 . 扩展功能提交
package java01;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.TreeMap;
public class Test {
// 统计数字或者字符出现的次数
public static TreeMap<Character, Integer> Pross(String str) {
char[] charArray = str.toCharArray();
TreeMap<Character, Integer> tm = new TreeMap<Character, Integer>();
for (int x = 0; x < charArray.length; x++) {
if (!tm.containsKey(charArray[x])) {
tm.put(charArray[x], 1);
} else {
int count = tm.get(charArray[x]) + 1;
tm.put(charArray[x], count);
}
}
return tm;
}
public static void main(String[] args) {
BufferedReader br = null;
int line = 0;
int count=0;
String str = "";
StringBuffer sb = new StringBuffer();
try {
br = new BufferedReader(new FileReader("C:\\Users\\asus\\Desktop\\1.txt")); // NOPMD by asus on 18-10-19 上午10:15
while ((str = br.readLine()) != null) {
sb.append(str);
++line;
}
String s=new String(sb);
String [] arr = s.split("\\s+|\\,|\\,");
for(String ss : arr){
System.out.println("单词内容"+ss);
count++;
}
System.out.println("字符总数: "+s.length());
System.out.println("单词个数为: "+count);
System.out.println("\n文件行数: " + line);
System.out.println("\n文件内容: " + sb.toString());
TreeMap<Character, Integer> tm = Pross(sb.toString());
System.out.println("\n字符统计结果为:" + tm);
System.out.println(args[0]);
System.out.println(args[1]);
System.out.println(args[3]);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/zy1054988241/wordCount3.git
git@gitee.com:zy1054988241/wordCount3.git
zy1054988241
wordCount3
wordCount3
master

搜索帮助