使用随机数类产生验证码
import java.util.Random;
/*
* 验证码
*/
public class Demo16 {
public static void main(String[] args) {
char[] arr = {'我','是','a','b','中','c','e','g'};
StringBuilder sb = new StringBuilder();
Random rd = new Random();
int index = 0;
int len = arr.length;
for(int i=0; i<4; i++)
{
index = rd.nextInt(len);
sb.append(arr[index]);
}
//输出验证码
System.out.println(sb);
}
}