1 //随机验证码,有数字、字符 2 //生成随机数,然后再截取,还要限定随机数的范围 3 String zimu = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890" ; 4 Random rm = new Random(); //生成随机数 5 6 int a = rm.nextInt(61); //0到61之间的随机数赋值给a 7 int b = rm.nextInt(61); 8 int c = rm.nextInt(61); 9 int d = rm.nextInt(61); 10 11 char zf = zimu.charAt(a); //将数组中索引为a的字符赋给zf 12 char zd = zimu.charAt(b); 13 char zc = zimu.charAt(c); 14 char zq = zimu.charAt(d); 15 16 System.out.println("请输入验证码: "+ zc +" " + zf +" " + zq +" " + zd);
//输出汉字字符