public class TestCharA
{
public static void main(String[] args)
{
char[] ch = {'a','b','a','c','c','d'};
char[] c1 = new char[ch.length];
int[] i1 = new int[ch.length];
int num = 0;
for(int i=0;i<ch.length;i++){
boolean f = true;
int j = 0;
for(;j<num;j++){
if(c1[j]==ch[i]) {
f = false;
break;
}
}
if(f){
c1[num] = ch[i];
i1[num] = i1[num]+1;
num ++;
}else{
i1[j] = i1[j]+1;
}
}
for(int i=0;i<num;i++){
System.out.println(c1[i]+":"+i1[i]);
}
}
}
如何理解?其中的boolean有什么用?
{
public static void main(String[] args)
{
char[] ch = {'a','b','a','c','c','d'};
char[] c1 = new char[ch.length];
int[] i1 = new int[ch.length];
int num = 0;
for(int i=0;i<ch.length;i++){
boolean f = true;
int j = 0;
for(;j<num;j++){
if(c1[j]==ch[i]) {
f = false;
break;
}
}
if(f){
c1[num] = ch[i];
i1[num] = i1[num]+1;
num ++;
}else{
i1[j] = i1[j]+1;
}
}
for(int i=0;i<num;i++){
System.out.println(c1[i]+":"+i1[i]);
}
}
}
如何理解?其中的boolean有什么用?
解决方案 »
- 汉字字符为什么会大于255?有代码。高手请指教
- 菜鸟提问
- setActionCommand()与getActionCommand() 的问题...
- JAVA连接Access数据库的代码
- 怎么总出现"the document has no page!"!!!!!!
- JMF问题。高分求助
- 怎么用jikes编译程序啊?
- 请问在sql server 2000 中一个表的text字段怎么取出来啊
- 请教jar文件中的manifest.mf有什么用?如何用?
- 继承,重写,静态方法的混合
- 需安装下载的hiberate插件软件?
- The method readLine() from the type DataInputStream is deprecated
i1[] 用来记录出现字符的次数
boolean f
用来控制c1[]中的字符是否在ch[]中已经出现过.若出现过,就直接在对应的i1[]中加1