// 调用方法并直接打印结果
System.out.println(getIdentifyingCode(6));
public static String getIdentifyingCode(int s) {
// 声明一个String类型str作为随机数取值的范围
String str = "qwertyuipasdfghjkzxcvbnmQWERTYUIPASDFGHJKLZXCVBNM23456789";
// 先准备一个String类型变量code,赋值"",用来拼接字符串验证码的
String code = "";
// 获取随机数ThreadLocalRandom对象
ThreadLocalRandom current = ThreadLocalRandom.current();
循环n次,每次循环先获取一个随机数作为字符串下标,下标范围
// 循环次数s次,因为是s为验证码
for (int i = 0; i < s; i++) {
// 每次循环先获取一个随机数作为字符串下标,下标范围
int nextInt = current.nextInt(0, str.length());
// 通过String对象str中方法获取一个字符
char charAt = str.charAt(nextInt);
// 拼接到code中
code += charAt;
}
// 循环结束后,将code返回
return code;
}
// 调用方法并直接打印结果
System.out.println(getIdentifyingCode(6));
public static String getIdentifyingCode(int s) {
// 声明一个String类型str作为随机数取值的范围
String str = "qwertyuipasdfghjkzxcvbnmQWERTYUIPASDFGHJKLZXCVBNM23456789";
// 先准备一个String类型变量code,赋值"",用来拼接字符串验证码的
String code = "";
// 获取随机数ThreadLocalRandom对象
ThreadLocalRandom current = ThreadLocalRandom.current();
循环n次,每次循环先获取一个随机数作为字符串下标,下标范围
// 循环次数s次,因为是s为验证码
for (int i = 0; i < s; i++) {
// 每次循环先获取一个随机数作为字符串下标,下标范围
int nextInt = current.nextInt(0, str.length());
// 通过String对象str中方法获取一个字符
char charAt = str.charAt(nextInt);
// 拼接到code中
code += charAt;
}
// 循环结束后,将code返回
return code;
}