随机产生验证码
使用String来开发验证码。需求如下:
需求:
实现随机产生验证码,验证码的每位可能是数字、大写字母、小写字母。
import java.util.Random;
public class Randoms {
//随机九位验证码(包含大小写和数字)
static Random ro = new Random();
public static void main(String[] args) {
verificationCode(3);
}
public static void verificationCode(int count){
String password = "";
for(int i = 0 ; i < count ; i ++){
int num = ro.nextInt(10);
num +=48;
char nums = (char)num;
int upper = ro.nextInt(26);
upper += 65;
char uppers = (char)upper;
int lower = ro.nextInt(26);
lower += 97;
char lowers = (char)lower;
password = password + nums+uppers+lowers;
}
System.out.println(password);
char[] passwords= password.toCharArray();
for(int i = 0 ; i < passwords.length; i++){
int bb = ro.nextInt(passwords.length);
System.out.print(passwords[bb]+"\t");}
}
}