Home > Back-end >  Please help on Java
Please help on Java

Time:10-03

In Java, generate 10 groups randomly six-figure authentication code (case-sensitive alphanumeric combination) run results, as seen here thank you

CodePudding user response:

For example

 
Import the Java. Util. HashSet;
Import the Java. Util. Random;
Import the Java. Util. Set;
Public class Sample {
Public static void main (String [] args) {
Char [] keys="0123456789 abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz". ToCharArray ();
The Random ran=new Random ();
Set The set=new HashSet<> (a);
The StringBuilder buf=new StringBuilder ();
While (set. The size () & lt; 10) {
Buf. Delete (0, buf. Length ());
for (int i=0; I & lt; 6; I++) {
Buf. Append (keys [ran nextInt (keys) length)]);
}
String s=buf. ToString ();
if (! The set contains (s)) {
Set. The add (s);
}
}
For (String s: set) {
System. The out. Printf (" random authentication code: % s \ n ", s);
}
}
}
  • Related