用java生成6为验证码,要求大小写,数字,不能重复字符

急... 展开
 我来答
旅初彤2B
2017-03-23 · TA获得超过2.6万个赞
知道大有可为答主
回答量:4.4万
采纳率:65%
帮助的人:5284万
展开全部
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());
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式