我想做一个程序,要实现的功能是,输入一篇英文,然后统计一下单词的出现频率,我没有一点思路啊,有高手指教一下啊,谢谢了
解决方案 »
- split
- java button监听,点击后setEnabled(false)
- spring rmi
- java 如何实现远程的文件上传下载?
- 程序结果与我预想的不一样.....请教
- 问一个关于软件发布的问题,很急,在线等答案
- 文件读写问题
- one.addItemListener(this); 什么意思
- Help me please......关于pop3协议>>>(要再加分可面谈)
- 通过JDBC连接数据库,执行抄作后,关闭了连接,数据服务器端的进程还在,怎麽处理?
- HashMap中的key不能重复,因此必须实现hashCode和equals方法
- 郁闷ing...求高人指点(ClassCastException)
import java.io.File;
import java.io.FileReader;
import java.io.IOException;public class ReadLine { public static void main(String[] args) {
BufferedReader reader = null;
try {
File readFile = new File("D://Projects//Paper.txt");
reader = new BufferedReader(new FileReader(readFile));
String temp = null;
int line = 1;
while ((temp = reader.readLine()) != null) {
System.out.println("Line" + line + ":" + temp);
line++;
}
reader.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
}
}
public static void main(String[] args) {
//输出aa出现的次数
String s=" a aa aa aaa aa a aa aa aaa aa ";
int sum=0;
int a=0;
int c=0;
while(a!=-1){
a=s.indexOf(" aa ",c);
c=a+3;
sum++;
}
System.out.println("the word \"aaa\" has appead "+(sum-1)+" times");
}}我也是初学者,楼主的问题,我也不知道怎么解决,这个是我的一个思路,也存在很多问题,我也不知道怎么解决。
坐等高手
(2)C语言中的strtok()函数或许对你有帮助。
try {
BufferedReader br = new BufferedReader(new FileReader("D:\\fan.java"));
String line = "";
while((line=br.readLine()) != null) {
Pattern p = Pattern.compile("fclxyz");
Matcher m = p.matcher(line);
while(m.find()) {
count++;
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.print(count);
}我去查了一下,这个应该可以,这个程序是查fan.java中fclxyz出现的次数