java如何实现a-z,0-9组成3个字符密码,将可能密码组合全部打印出
2个回答
2012-10-16
展开全部
以前写着玩的,用于枚举登录密码的。。。
public class Test2 {
private final static String bk = "0123456789abcdefghijklmnopqrstuvwxyz";
public static void main(String[] args) {
String cur = "zz";
while((cur = getNext(cur)).length() < 4) {
System.out.println(cur);
}
}
private static String getNext(String cur) {
if(cur.length() == 0)
return bk.charAt(0) + "";
int len = bk.length();
String ret = "";
char[] cs = cur.toCharArray();
for(int i = cs.length - 1; i > -1; i--) {
int p = bk.indexOf(cs[i] + "");
if(p == len - 1) {
ret += bk.charAt(0);
if(i == 0) {
return bk.charAt(0) + ret;
}
} else {
ret = cur.substring(0, i) + bk.charAt(p + 1) + ret;
return ret;
}
}
return ret;
}
}
public class Test2 {
private final static String bk = "0123456789abcdefghijklmnopqrstuvwxyz";
public static void main(String[] args) {
String cur = "zz";
while((cur = getNext(cur)).length() < 4) {
System.out.println(cur);
}
}
private static String getNext(String cur) {
if(cur.length() == 0)
return bk.charAt(0) + "";
int len = bk.length();
String ret = "";
char[] cs = cur.toCharArray();
for(int i = cs.length - 1; i > -1; i--) {
int p = bk.indexOf(cs[i] + "");
if(p == len - 1) {
ret += bk.charAt(0);
if(i == 0) {
return bk.charAt(0) + ret;
}
} else {
ret = cur.substring(0, i) + bk.charAt(p + 1) + ret;
return ret;
}
}
return ret;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询