如题
解决方案 »
- 一个小技巧不知道,希望大家解决?
- 什么时候回收垃圾
- 小弟我在学习过程中,从来没有见到过这样奇怪的问题,我真的想不通了
- 如何判断一个其间包含了哪几个月?
- 请为什么这个双检测单例对象不行
- 有关端口占用的问题
- 我为什么运行不了sun j2sdkee1.3 doc中的sample :Converter?
- 好容易找到个向女孩献殷勤的机会
- 请问高手,toolkit这个类是什么设计模式?
- System.out.println((char)165573);
- 100分求这是什么异常?javax.xml.ws.WebServiceException: No Content-type in the header!
- JOptionPane.showMessageDialog(this,"You input number is Wrong!!!(0~100)","Error",JOptionPane.ERROR_MESSAGE);问题
看分割之后的数组size即可
import java.util.regex.Pattern;public class Test {
public static void main(String[] args) {
int count = 0;
String regex = "[\\u4e00-\\u9fa5]";
String str = "中华人民共和国zhonghuarenmingongheguo";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(str);
System.out.print("提取出来的中文有:");
while (m.find()) {
count++;
System.out.print(m.group() + " ");
}
System.out.println();
System.out.println("汉字出现的频率:"+count);
}
}
String mystr; DDD(String x) {
mystr = x;
} void str_convert() {
char my;
char[] str1 = mystr.toCharArray();
// 查找每个字符出现的次数
for (int i = 0, b = mystr.length(); i < mystr.length(); i++) {
int c1 = 0;
my = mystr.charAt(i);
for (int k = 0; k < b; k++) {
if (my==str1[k]) {
c1++;
}
}
System.out.println("字符 " + my + " 出现的次数为:" + c1);
}
}
}class Test {
public static void main(String args[]) {
DDD num = new DDD("汉字收到了看见发可是大家分开江苏大汉字");
num.str_convert();
}
}
private static final int ONE=1;
public static void main(String[] args){
Map m = new HashMap();
int b=0;
FileReader fis;
try {
fis = new FileReader("F:\\java\\myword.txt");
while( (b=fis.read())!=-1){
Integer freq = (Integer)m.get((char)b);
m.put((char)b,(freq==null?ONE:new Integer(freq.intValue()+1)));
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(m.size()+"------");
System.out.println(m);
}
}
private static final int ONE=1;
public static void main(String[] args){
Map m = new HashMap();
int b=0;
FileReader fis;
try {
fis = new FileReader("F:\\java\\myword.txt");
while( (b=fis.read())!=-1){
Integer freq = (Integer)m.get((char)b);
m.put((char)b,(freq==null?ONE:new Integer(freq.intValue()+1)));
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(m.size()+"------");
System.out.println(m);
}
}
import java.util.ArrayList;//统计一段文本中汉字出现的频率
public class StaticPin { /**
* @param args
*/
public void Static(String str) {
ArrayList<Character> al = new ArrayList<Character>();
for (int i = 0; i < str.length(); i++) {
al.add(i, str.charAt(i));
} while (al.size()!=0) {
int count = 1;
for (int j = 1; j < al.size() ; j++) {
if (al.get(0).equals(al.get(j))) {
al.remove(j);
count++;
}
}
System.out.println(al.get(0)+" 出现了"+count+"次");
al.remove(0);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
String str="中国奥运会成功举办,中国人是好样的";
StaticPin sp=new StaticPin();
sp.Static(str);
}}
package Str1;
import java.util.*;
public class Test {
private static final int ONE=1;
public static void main(String[] args) {
Map l1=new HashMap();
String str="中华人民共和国中国共产党";
char[] ch=str.toCharArray();
for(int i=0;i<str.length();i++){
Integer freq=(Integer)l1.get(ch[i]);
l1.put(ch[i],(freq==null?ONE:freq.intValue()+1));
}
System.out.println(l1);
}
}
输出结果:{共=2, 产=1, 中=2, 党=1, 和=1, 人=1, 华=1, 国=2, 民=1}
//如果map1 已经包含了这个字符那么 map2.put(key,map2.get(key)+1);
map2,里面存放的是这个字符在串里面出现的次数
}for 循环结束后还要for 循环 map2 用map2.get(key)/字符串的长度就是没有字符出现的平率!!
//如果map1 已经包含了这个字符那么 map2.put(key,map2.get(key)+1);
map2,里面存放的是这个字符在串里面出现的次数
}for 循环结束后还要遍历 map2 用map2.get(key)/字符串的长度就是没有字符出现的平率!!