隨機生成6位驗證碼或密碼(字母和數字組合)
阿新 • • 發佈:2019-01-09
import java.util.Random;
public class Test {
public static char[] getChar(){
char[] passwordLit = new char[62];
char fword = 'A';
char mword = 'a';
char bword = '0';
for (int i = 0; i < 62; i++) {
if (i < 26) {
passwordLit[i] = fword;
fword++;
}else if(i<52){
passwordLit[i] = mword;
mword++;
}else{
passwordLit[i] = bword;
bword++;
}//方法的抽取,按功能
//System.out.println(passwordLit[i]);
}
return passwordLit;
}
public static void main(String[] args) {
char[] r = getChar();
Random rr = new Random();
char[] pw= new char[6];
for(int i=0;i<pw.length;i++){
int num = rr.nextInt(62);
pw[i]=r[num];
System.out.print(pw[i]+" ");
}
}
}
public class Test {
public static char[] getChar(){
char[] passwordLit = new char[62];
char fword = 'A';
char mword = 'a';
char bword = '0';
for (int i = 0; i < 62; i++) {
if (i < 26) {
passwordLit[i] = fword;
fword++;
}else if(i<52){
passwordLit[i] = mword;
mword++;
}else{
passwordLit[i] = bword;
bword++;
}//方法的抽取,按功能
//System.out.println(passwordLit[i]);
}
return passwordLit;
}
public static void main(String[] args) {
char[] r = getChar();
Random rr = new Random();
char[] pw= new char[6];
for(int i=0;i<pw.length;i++){
int num = rr.nextInt(62);
pw[i]=r[num];
System.out.print(pw[i]+" ");
}
}
}