//输出5位验证码,前4位为大写或小写字母,后一位为数字
import java.util.Random;
public class Test {
public static void main(String[] args) {
//将小写字母和大写字母添加到数组中
char[] chs = new char[52];
for (int i = 0; i < chs.length; i++) {
if (i <= 25) {
chs[i] = (char) (97 + i);//a:97
}else {
chs[i] = (char) (65 + i-26);//A:65
}
}
//定义字符串,用来记录最终结果
String result = "";//初始为空
//字母--随机抽取4次
Random r = new Random();
for (int i = 0; i < 4; i++) {
//用随机索引---获得随机字母
int randomIndex = r.nextInt(52);//随机索引范围:0~51
char ziMu = chs[randomIndex];
result = result + ziMu;
}
//生成随机数字0~9
int num = r.nextInt(10);
//打印结果
result = result + num;
System.out.println(result);
}
}