The Java Foundation------generate a six-digit verification code (with uppercase, lowercase letters, numbers, and no duplicates)?

Source: Internet
Author: User

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)?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.