Joke Collection Website - Public benefit messages - Generate a 6-digit verification code with java, which consists of uppercase and lowercase letters and cannot repeat characters.
Generate a 6-digit verification code with java, which consists of uppercase and lowercase letters and cannot repeat characters.
Public? Class? GenerateRandomLetterAndNum? {
Public? Static electricity Invalid? main(String[]? args)? {
? Set< string & gt? Shop? =? getletterandnum(6);
?
? PrintSet (shop);
}
Public? Static electricity Set< string & gt? getletterandnum(int? Length)? {
Set< string & gt? Settings? = new? HashSet & lt string & gt ();
For what? (int? Me? =? 0; ? Me? & lt? Length; ? i++)? {
String? Value? =? get random();
Set.add (value);
}
What if? (set . size()& lt; Length)? {? //If 6 bits are not generated
String? Value? =? get random(); //Continue to call the method of generating random numbers.
Set.add (value);
}
Return? Settings;
}
Private? Static electricity String? getrandom()? {? //method for generate random letters and number
String? Value? =? "";
Random? Random? =? New? random();
int? gen? =? random . nextint(2); //0、 1、2
String? Charonam? =? gen? %? 2? ==? 0“char”? :? "Num";
What if? (“char”。 Is equal to (charornum)? {
int? Temporary workers? =? random.nextInt(2)? %? 2? ==? 065? :? 97;
int? ascii? =? random . nextint(26);
Value? +=? (char)? (ascii? +? temp);
}? Or what? What if? (“num”。 equalsIgnoreCase(charornum))? {
Value? +=? string . value of(random . nextint( 10));
}
Return? Value;
}
Public? Static electricity Invalid? printSet(Set? set){? //Method of printing settings
? Iterator? Iterator? =? set . iterator();
? What time? (iterator.hasNext())? {
String? ele? =? (string)? iterator . next();
System.out.print(ele+"?" );
}
}
- Previous article:If yes, how to intercept SMS?
- Next article:Wechat business, good night, text and pictures.
- Related articles
- How to write short messages?
- How does Guangdong Telecom check the phone bill?
- How long does it usually take to unblock the Shanghai control area?
- How to write the content of a return visit to kindergarten
- People always send verification messages to harass me. Can I find his IP through the verification message?
- Does Pinduoduo praise the cash back store?
- Frequently asked questions about renewal of public rental housing in Baoshan District, Shanghai
- Best wishes to good friends, mothers and children.
- How should women prevent being harassed in the workplace?
- How to say a blessing when a friend has a car accident?