1个回答
展开全部
public class test{
private static String [] str={"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","0","1","滑手唯2","3","4","5","6","7","8","9"};
private static String DarwCode(){
String strRandom="";
char temp;
int [] num = new int[6];
int numA=0,numB=0,numC=0,ramNum=(int)(Math.random()*62);
//去掉重复的关键代码
num[0]=ramNum;
for (int i = 1; i < num.length; i++) {
num[i] = (int)(Math.random()*62);
for (int j = 0; j < i; j++) {
while ((num[i]==num[j])&&(i>=1)) {
i--;
}
}
}
//输出字符串
for (int i = 0; i < num.length; i++) {
strRandom+=str[num[i]];
}
for (int i = 0; i <strRandom.length(); i++) {
temp=strRandom.substring(i,i+1).charAt(0);
if ((int)temp>=48&&(int)temp<=57) {
numA++;
}else if ((int)temp>=65&&(int)temp<=90) {
numB++;
}else if((int)temp>=97&&(int)temp<=122){
numC++;
}
}
if ((numA+numB==6)||(numA+numC==6)||(numB+numC==6)) {
strRandom = DarwCode();
}
return strRandom;
}
public static void main(String[] args) {
System.out.println(DarwCode());
}
}
private static String [] str={"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","0","1","滑手唯2","3","4","5","6","7","8","9"};
private static String DarwCode(){
String strRandom="";
char temp;
int [] num = new int[6];
int numA=0,numB=0,numC=0,ramNum=(int)(Math.random()*62);
//去掉重复的关键代码
num[0]=ramNum;
for (int i = 1; i < num.length; i++) {
num[i] = (int)(Math.random()*62);
for (int j = 0; j < i; j++) {
while ((num[i]==num[j])&&(i>=1)) {
i--;
}
}
}
//输出字符串
for (int i = 0; i < num.length; i++) {
strRandom+=str[num[i]];
}
for (int i = 0; i <strRandom.length(); i++) {
temp=strRandom.substring(i,i+1).charAt(0);
if ((int)temp>=48&&(int)temp<=57) {
numA++;
}else if ((int)temp>=65&&(int)temp<=90) {
numB++;
}else if((int)temp>=97&&(int)temp<=122){
numC++;
}
}
if ((numA+numB==6)||(numA+numC==6)||(numB+numC==6)) {
strRandom = DarwCode();
}
return strRandom;
}
public static void main(String[] args) {
System.out.println(DarwCode());
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询