import java.io.*;
我們提供的服務有:成都做網(wǎng)站、網(wǎng)站設計、外貿(mào)營銷網(wǎng)站建設、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認證、新巴爾虎右ssl等。為近1000家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務,是有科學管理、有技術(shù)的新巴爾虎右網(wǎng)站制作公司
import java.util.Scanner;
public class pinlv {
public static void main(String[] args) throws Exception {
Scanner input = new Scanner(System.in);
System.out.print("Enter a filename: ");
String filename = input.nextLine();
BufferedInputStream fileInput = new BufferedInputStream(
new FileInputStream(new File(filename)));
int[] counts = new int[128];
int r;
while ((r = fileInput.read()) != -1 ) {
counts[(byte)r]++;
}
System.out.printf("%15s%15s\n", "char", "Counts");
for (int i = 0; i counts.length; i++)
if (counts[i] != 0)
System.out.printf("%15c%15d\n", i, counts[i]);
}
}
/**
*?@content?Java交流群:?178048291
*?取頻率最高的結(jié)果集
*/
private?static?SetInteger?MaxRate(int[]?arrs)?{
//?統(tǒng)計個數(shù)字的頻率
MapInteger,?Integer?map?=?new?HashMap();
for?(int?i?=?0;?i??arrs.length;?i++)?{
if?(arrs[i]?==?0)?{
break;//?為0則結(jié)束統(tǒng)計
}
if?(map.containsKey(arrs[i]))?{
map.put(arrs[i],?map.get(arrs[i])?+?1);
}?else?{
map.put(arrs[i],?1);
}
}
int?maxtime?=?1;?//?出現(xiàn)頻數(shù)
SetInteger?set?=?new?HashSet();//?最高頻率的結(jié)果集
//?得出最高頻率的數(shù)
for?(Map.EntryInteger,?Integer?entry?:?map.entrySet())?{
if?(entry.getValue()??maxtime)?{
maxtime?=?entry.getValue();//?新最高頻數(shù)
set.removeAll(set);
set.add(entry.getKey());
}?else?if?(entry.getValue()?==?maxtime)?{
set.add(entry.getKey());
}
}
return?set;
}
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class Test {
private BufferedReader buf;
public void frequency(String word, String file) {
try {
buf = new BufferedReader(new FileReader(file));
String str = "";
int count = 0;
while ((str = buf.readLine()) != null) {
int index = 0;
while (index != -1) {
index = str.indexOf(word);
if (index == -1) {
break;
}
str = str.substring(index + word.length(), str.length());
count++;
}
}
System.out.println(count);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Test test = new Test();
test.frequency("百度", "data.txt");
}
}
//不懂百度HI我~
哈哈,這個是一種思想,不過也不算復雜的。
比如代碼:
String testStr="a1b2c3d4e5";
//這個字符串的長度是10。我們假設就有10個不同的字符。
//用一張2列10行的二維表來描述該情況!這張二維表的第一列表示新出現(xiàn)的字符,對應的第二列表示該字符出現(xiàn)的次數(shù)!
主要還是數(shù)組遍歷查找,得到所有字符(不重復)放到一個2維的存儲結(jié)構(gòu),然后繼續(xù)統(tǒng)計這些字符的出現(xiàn)次數(shù)。
網(wǎng)站名稱:統(tǒng)計搜索頻率代碼Java java高頻詞統(tǒng)計
當前網(wǎng)址:http://chinadenli.net/article12/dogdggc.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供電子商務、建站公司、網(wǎng)站設計、標簽優(yōu)化、網(wǎng)站內(nèi)鏈、面包屑導航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)