/**
* 随机生成6位验证码
*
* @author guojing
*/
public class VerificationCode {
public static void main(String[] args) {
String[] str = {"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", "L", "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", "l", "s", "t", "u", "v", "w", "s", "y", "z"};
String strCode = "";
int len = 6; //生成验证码的长度
int number = 0;
for (int j = 0; j < len; j++) {
for (int i = 0; i <= str.length; i++) {
number = (int) (Math.random() * str.length);
}
strCode += str[number];
}
System.out.println(strCode);
}
}
运行结果: