【JAVA文件读取txt文本方式并词频统计】教程文章相关的互联网学习教程文章

【JAVA】高频单词统计器(附教程)【代码】

视频教程. package EngLishPackage;import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*;public class Note implements ActionListener {private MyFrame _myFrame;private JLabel _label;private JButton _openBtn;private JButton _saveBtn;private JTextArea _textArea;public static HashMap<String, Integer> map = new HashMap<String, Integer>();public static Stri...

PAT个位数统计(15分)【java】【代码】【图】

怎么说呢,网上的答案我都不是很喜欢,就自己写了 就一眼就懂得。。。 //import java.awt.image.RescaleOp; import java.util.Scanner;//个数统计 public class Main {public static void main(String[] args) {Scanner scanner=new Scanner(System.in);//String n=scanner.next();int n=scanner.nextInt();int[] b=new int[10];int count=0;while (n>0) {int a=n%10;b[a]+=1;n=n/10;}for (int i = 0; i < b.length; i++) {if (b[i...

java统计集合中每个元素出现的次数【代码】

Map<Integer, Integer> mapNum = new HashMap<>();for (Map<String, Object> edge : edges) {Integer source = Integer.valueOf(edge.get("source").toString());Integer target = Integer.valueOf(edge.get("target").toString());Integer count1 = mapNum.get(source);Integer count2 = mapNum.get(target);mapNum.put(source, (count1 == null) ? 1 : count1 + 1);mapNum.put(target, (count2 == null) ? 1 : count2 + 1);}

Java 统计字符串中每个字符出现的次数使用集合方法【代码】

1 import java.util.HashMap;2 import java.util.Scanner;3 import java.util.Set;4 5 public class MapTest {6 public static void main(String[] args) {7 Scanner scanner = new Scanner(System.in);8 //键盘录入字符串9 System.out.println("请输入一串字符"); 10 //创建字符串对象,存储键盘输入的值 11 String line = scanner.nextLine(); 12 //创建HashMap集合,键是c...

Java8使用Stream流实现List列表的查询、统计、排序、分组【代码】【图】

https://blog.csdn.net/pan_junbiao/article/details/105913518Java8提供了Stream(流)处理集合的关键抽象概念,它可以对集合进行的操作,可以执行非常复杂的查找、过滤和映射数据等操作。Stream API 借助于同样新出现的Lambda表达式,极大的提高编程效率和程序可读性。 下面是使用Stream的常用方法的综合实例。 创建UserService.class(用户信息业务逻辑类)。 import com.pjb.streamdemo.entity.User; import java.math.BigDeci...

使用java8的Stream统计字符串数组中每一个字符出现的次数【代码】

题目:有一个字符串数组["Hello world", "I am tom", "how are you!"],要求统计每一个字符出现的次数 实现的方式有很多种,可以考虑HashMap如果key重复则计数加一。比较简单就不写这种方式 如果使用java8的stream来完成这道题,我们可以先将字符串数组转换为字符流,然后进行分组即可完成任务,代码如下: Stream的方式实现统计 import java.util.ArrayList; import java.util.stream.Collectors; import java.util.stream.Stream...

JAVA与JS统计程序执行时间【代码】【图】

long startTime = System.currentTimeMillis(); //测试程序用时/*被测试程序 */long endTime = System.currentTimeMillis(); //获取结束时间System.out.println("程序运行时间:" + (endTime - startTime) + "ms");执行效果: console.time('time');/*被测试程序 */console.timeEnd('time'); 执行效果:

JAVA 统计字符串字母数字其他字符个数【代码】

这个初识java一定会遇到的基础题,可以参考学习下。 public class StringTest {public static void main(String[] args) {String strTest="1a2x4d _h.;q,56zx";StringTest.countByChar(strTest);StringTest.countByASCLLCode(strTest);StringTest.countByRegular(strTest);} 方法1:通过字符统计 public static void countByChar(String str){int numCount=0,charCount=0,otherCount=0;char temp;for (int i = 0; i < str.length()...

javaWeb中实现在线人数统计【代码】

第一步:创建一个实现HttpSessionListener接口的类 package com.my.count;import javax.servlet.http.*;public class SessionCounter implements HttpSessionListener {private static int activeSessions = 0;//session创建时执行public void sessionCreated(HttpSessionEvent se) {activeSessions++;}//session销毁时执行public void sessionDestroyed(HttpSessionEvent se) {if (activeSessions > 0)activeSessions--;}//获取活...

统计一个目录中有多少个.java文件【代码】

package cn.lyc;import java.io.File;public class File5 { //声明一个静态变量,方法中会用到 static int num = 0; public static void main(String[] args) { //文件路径 String path = "C:\\Users\\86176\\Desktop\\J"; //调用方法 query(new File(path)); //输出num(符合文件的个数) System.out.println(num); } //写一个新的方法 public static void query(Fil...

Java 多线程读取文件并统计词频 实例 出神入化的《ThreadPoolExecutor》【代码】

重在展示多线程ThreadPoolExecutor的使用,和线程同步器CountDownLatch,以及相关CAS的原子操作和线程安全的Map/队列。 ThreadPool主线程 1 import java.io.BufferedWriter;2 import java.io.File;3 import java.io.FileWriter;4 import java.util.*;5 import java.util.concurrent.*;6 import java.util.concurrent.atomic.AtomicInteger;7 import java.util.concurrent.atomic.AtomicReferenceArray;8 9 /** 10 * ClassName: Th...

Java 键盘输入字符串,统计字符,打印输出【代码】

/*键盘输入字符串,统计字符,打印输出分析:键盘输入用到Scannner ,字符char 输入的是字符串String String string = Scanner 字符有英文字母大小写,还有数字,以及其它字符 要定义四个变量用来存储这些字符 需要对字符串中的每个字符进行判断,用到toCharArray() 既然统计字符,那肯定用到判断 */import java.util.Scanner;public class DemoScannerSum { public static void main(String[] args) { ...

PTA 题解:jmu-Java&Python-统计文字中的单词数量并按出现次数排序【代码】【图】

目录题目说明题干测试数据 1输入样例输出样例测试数据 2输入样例输出样例题目分析去除标点符号统计词频单词排序 题目说明 题干测试数据 1 输入样例 failure is probably the fortification in your poleit is like a peek your wallet as the thief when you are thinking how to spend several hard-won leptawhen you are wondering whether new money it has laid background because of you then at the heart of themost lax ...

(OJ)Java常用类-统计数字次数【代码】

统计数字次数 Problem Description 命令行输入一个由数字组成的任意字符串,统计出每个数字出现的次数。Input Description 1239586838Output Description 0 counts:01 counts:12 counts:13 counts:24 counts:05 counts:16 counts:17 counts:08 counts:39 counts:1解题代码 import java.util.Scanner;public class Main{public static void main(String[] args) {// 创建Scanner对象 接收控制台输入Scanner in = new Scanner(System....

java:统计单词个数(题目都没看懂)【代码】

java:统计单词个数 题目 问题描述给出一个长度不超过200的由小写英文字母组成的字母串(约定;该字串以每行20个字母的方式输入,且保证每行一定为20个)。要求将此字母串分成k份 (1<k<=40),且每份中包含的单词个数加起来总数最大(每份中包含的单词可以部分重叠。当选用一个单词之后,其第一个字母不能再用。例 如字符串this中可包含this和is,选用this之后就不能包含th)。单词在给出的一个不超过6个单词的字典中。要求输出最大的个数...