统计单词个数以及倒序输出
来源:互联网 发布:centos无线网卡配置 编辑:程序博客网 时间:2024/06/04 18:20
public class EnglishNum { //统计单词个数 public static void main(String[] args){ String words = "Look buddy, U got work hard and put yourself in your java, Once you learned the heart of the java, I can guarantee that you win."; String reg = "[a-zA-Z]+"; Pattern p = Pattern.compile(reg); Matcher m = p.matcher(words); HashMap<String, Integer> map = new HashMap<String, Integer>(); int count = 0; while(m.find()){ count++; String w = m.group(); if(null == map.get(w)){ map.put(w, 1); }else{ int x = map.get(w); map.put(w, x + 1); } } System.out.println(count); System.out.println(map); } }
//倒序进行输出 public static void main(String [] args){ String words = "I come from China.";// String[] m =words.split("\\s");// for(int j =m.length-1;j>=0;j--){// System.out.print(m[j]+" ");// } Stack<String> stack = new Stack<>(); for(String s:words.split(" ")){ stack.push(s); } while(!stack.empty()){ System.out.print(stack.pop()+" "); } }
0 0
- 统计单词个数以及倒序输出
- 统计单词个数排序输出
- 实现一个字符串中单词个数的统计,并按照单词字典序输出单词以及单词的出现个数。使用strsep
- Python给定一个句子倒序输出单词以及字母
- java实现单词倒序输出
- vc 统计单词个数
- 统计单词个数
- 统计单词个数
- 统计单词个数
- 统计单词个数
- 统计单词个数
- 统计单词个数
- 状态机统计单词个数
- wikioi1040 统计单词个数
- C统计单词个数
- 统计不同单词个数
- 统计单词个数
- acm-统计单词个数
- BZOJ 3036
- 仿12306查询火车票功能
- android 测试开发概述
- 求逆序数
- Linux服务器如何自定义安装Redis
- 统计单词个数以及倒序输出
- jenkins+php+svn快速部署测试环境开发环境快速部署
- spring security:基于MongoDB的认证
- android应用前后台切换的监听
- uva 10137 the trip
- Android 属性动画(Property Animation) 完全解析 (上)
- 前端构建:Less入了个门
- Unity LayerMask用法
- HDU 3032.Nim or not Nim?【SG函数打表找规律】【4月11】