字符串顺序组合及对比,从a到z到zzzzz…
(自己第一篇博文,内容及排版十分简陋,多多担待,练习使用中。)
// An highlighted block
public static void main(String[] args) {
String key3 = " ";
java.lang.String[] S3 = new String [30];
int a,b,c,d,e,f,g;
S3 [0]="a";
S3 [1]="b";
S3 [2]="c";
S3 [3]="d";
S3 [4]="e";
S3 [5]="f";
S3 [6]="g";
S3 [7]="h";
S3 [8]="i";
S3 [9]="j";
S3 [10]="k";
S3 [11]="l";
S3 [12]="m";
S3 [13]="n";
S3 [14]="o";
S3 [15]="p";
S3 [16]="q";
S3 [17]="r";
S3 [18]="s";
S3 [19]="t";
S3 [20]="u";
S3 [21]="v";
S3 [22]="w";
S3 [23]="x";
S3 [24]="y";
S3 [25]="z";
//创建数组S3[],赋予a~z
authkey6="abcde"
boolean state = true;
for(a=0;a<=25&&state;a++) {
for(b=0;b<=25&&state;b++) {
for(c=0;c<=25&&state;c++) {
for(d=0;d<=25&&state;d++) {
for(e=0;e<=25&&state;e++) {
key3=S3[a]+S3[b]+S3[c]+S3[d]+S3[e];
//转为字符串
System.out.println(key3);
if(authkey.equals(key3)){
System.out.println("==========================对比成功======================");
System.out.println("key3");
state = false;
//对比成功跳出,
}
else System.out.println("false"+"-"+a+"-"+b+"-"+c+"-"+d+"-"+e);
//对比失败,输出组合顺序
}
}
}
}
}
}
state貌似只要在最内层循环的for中即可,第一次用这个,也是在别的博主文章中看到的这种跳出循环的方法,emm,在后面文章中介绍一下那几种循环的性能吧。
如这样,就实现了authkey跟key3的对比并在成功后跳出