演示代码如下:
Demo03 de = new Demo03();
de.C3(10);
//abc();
System.out.println(getPwd(6));
System.out.println(getPwd(10));
System.out.println(getPwd(12));
System.out.println(getPwd(32));
System.out.println(getPwd(64));
}
public static String getPwd(int len) {
char[] str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*-=<>/`~?_".toCharArray();
String password = "";
Random rand = new Random();
for (int i = 0; i < len; i++) {
char c = str[rand.nextInt(str.length)];
password += String.valueOf(c);
}
return password;
}
运行结果如下:
————————————————
版权声明:本文为CSDN博主「fpl1116」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_62124267/article/details/131712591