欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

統(tǒng)計搜索頻率代碼Java java高頻詞統(tǒng)計

統(tǒng)計一個文本里每個字母出現(xiàn)的頻率 用java 寫的

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]);

}

}

統(tǒng)計輸入數(shù)字頻率java

/**

*?@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;

}

統(tǒng)計一個詞在一個txt中的頻率。 java

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我~

java語言怎么統(tǒng)計一個給定字符串中指定字符出現(xiàn)的頻率(次數(shù))?

哈哈,這個是一種思想,不過也不算復雜的。

比如代碼:

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)

成都網(wǎng)頁設計公司