import java.util.HashMap;
import java.util.Map;
公共类计数通道{
//*
* JAVA编程问题:字符串' yekmaakkccekymbvb '计算字符串中有多少种字符以及每个字符的个数?
*
*/
publicstaticvoidmain (字符串[ ] args ) {
stringa string=' yekmaakkccekymbvb ';
int count=0;
字符串单字符串=';
Map stringMap=new HashMap (;
for(intI=0; i aString.length (; I ) {
单字符串=string.value of (a string.charat (I ) );
system.out.println (单字符串;
countcharnumccn=new count charnum (;
//第一次出现的文字
if (string map.get (单字符串)==null ) {
计数=0;
} else {
计数=(integer ) stringmap.get ) singlestring;
}
string map.put (单字符串,count 1;
}
system.out.println (字符串映射;
}
}
公共类stringsplit {
//*
*编程:创建用于剪切字符串的函数,将其作为字符串和字节数输入,并作为每字节剪切出的字符串输出。 但是,为了不像“我ABC”4那样分割一半汉字,
*应该切“我AB”,输入“我ABC汉def”6,输出“我ABC”而不是“我ABC汉的一半”。
*
* @param args
*/
字符串分割字符串;
int splitBytes;
公共字符串分割(字符串分割字符串,int splitBytes )。
super (;
this.splitString=splitString;
this.splitBytes=splitBytes;
system.out.println (the string is : ) splitstring
',thesplitbytesis : ' split bytes;
}
公共语音剥离(
int num=0;
StringBuffer sb=new StringBuffer (;
int i=0;
if (分割字节=2) {
while(numsplitbytes ) {
(if(splitstring.substring(I,i 1).matches ) (((u4e 00-(u9fa5) ) ) ) ) ) 65 )
num =2;
} else {
num;
}
sb.append (split string.substring ) I,i 1);
I;
}
system.out.println (' final string : ' sb.tostring ) );
}
}
publicstaticvoidmain (字符串[ ] args ) {
StringSplit ss=new StringSplit ('我ABCD的母亲e的父亲f ',5 );
ss.splitIt (;
}
}
package com.searchkiller;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
公共班级Alpha Asc {
/**Java编程问题:字符串sbc、fds、des按照字母的升序输出
* @param args
*/
publicstaticvoidmain (字符串[ ] args ) {
String[] aString={'sbc '、' fds '、' des'};
列表列表=new ArrayList (;
for(intI=0; i aString.length; I ) {
list.add(astring[I];
}
collections.sort (列表;
system.out.println (列表;
}
}
共享到:
2009-09-09 08:39
阅览2821
评论