JAVA_SE基础——71.Random类制作随机验证码

时间:2021-10-04 06:23:38
public class Demo5 {
public static void main(String[] args) { char[] arr={'s','b','g','h','a','c'};
StringBuilder sb=new StringBuilder();
Random random=new Random();
for(int i=0;i<4;i++){
int index=random.nextInt(arr.length);
sb.append(arr[index]);
}
System.out.println("验证码:"+sb);
} }