package pxc.cn;
import java.util.Random;
public class student {
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
}else{
chs[i]=(char)(65+i-26);//大写字母A
}
}
//随机字母四遍
//变量接收
String result="";
Random r=new Random();
for (int i = 0; i <4 ; i++) {
int sj=r.nextInt(chs.length);
result=result+chs[sj];
}
//随机数字1到9
int number=r.nextInt(10);
result=result+number;
System.out.println(result);
}
}
生成五位随机数验证码(前四位字母大小写 后一位数字)
最新推荐文章于 2024-05-31 10:46:10 发布