package demo02;
/*
随机验证码。
- 随机生成十组六位字符组成的验证码。
- 验证码由大小写字母、数字字符组成。
*/
import java.util.ArrayList;
import java.util.Random;
public class Test01 {
public static void main(String[] args) {
// 1.使用数组创建一个字典,包含大小写字母、数字字符
char[] arr = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z'};
Random random =new Random();
for (int i = 0; i < 10; i++) {
String str="";
for (int i1 = 0; i1 < 6; i1++) {
int num = random.nextInt(arr.length);
str=str+arr[num];
}
System.out.println("随机验证码: "+str);
}
}
}
转载:https://blog.csdn.net/Don_11/article/details/106473917
查看评论