public static void main(String[] args){
String str = "qwertyuiopasdfghjklzxcvbnm0123456789ZXCVBNMASDFGHJKLPOIUYTREWQ";
Scanner sc = new Scanner(System.in);
System.out.println("你想取几位随机数 : ");
int a = sc.nextInt();
String s = "";
char[] arr = new char[a];
Random random = new Random();
for (int i = 0; i < a; i++) {
int b = random.nextInt(str.length());
arr[i] = str.charAt(b);
}
for (int i = 0; i < arr.length; i++) {
s += arr[i];
}
System.out.println(s);
}
2.数字字母分类讨论,char数组 ASCII码法
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("随机几位数的验证码 : ");