Problem Description: Generate a six-digit verification code that contains uppercase letters, lowercase characters, numbers, and does not allow duplicates?
The reference code is as follows:
Import Java.util.Arrays;
Import Java.util.Random;
public class verifcode{
public static void Main (string[] args) {
1. Generates an array of all the valid characters that the CAPTCHA can fetch
string[] letters={"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
"O", "P", "Q", "R", "s", "T", "U", "V", "w", "X", "Y", "Z",
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
"O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
int len=letters.length;
2. Define an array to identify the characters that have been used in the letters array, and the used characters cannot be reused
Boolean[] Flags=new Boolean[len]; Note: The default value for each item of a Boolean array is False
Random ran=new random ();
3. Define an array to hold the generated verification code
String[] Chs=new string[6];
for (int i=0;i<chs.length;i++) {
int num=0;
Generate a character that has not been used
bo=
Num=ran.nextint (len);
}while (Flags[num]);
Chs[i]=letters[num];
Flags[num]=true;
}
SYSTEM.OUT.PRINTLN ("generated six-bit verification code is:" +arrays.tostring (CHS));
}
}
The Java Foundation------generate a six-digit verification code (with uppercase, lowercase letters, numbers, and no duplicates)?