<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->import java.io.*;
public class AuthCode{
public static void main(String[] args){
char[] characters={'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','1','2','3','4','5','6','7','8','9','0'};
char[] fourResult=new char[4];
int index;
for (int k=0;k<4;k++ ){
index=(int)(Math.random()*62);
fourResult[k]=characters[index];
}
for(int i=0;i<4;i++)
System.out.println(fourResult[i]);
}
}
结果是随机的四个数字或字母组合:
edio
aB09
public class AuthCode{
public static void main(String[] args){
char[] characters={'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','1','2','3','4','5','6','7','8','9','0'};
char[] fourResult=new char[4];
int index;
for (int k=0;k<4;k++ ){
index=(int)(Math.random()*62);
fourResult[k]=characters[index];
}
for(int i=0;i<4;i++)
System.out.println(fourResult[i]);
}
}
结果是随机的四个数字或字母组合:
edio
aB09
本文介绍了一个简单的Java程序,用于生成包含四个随机字符(字母或数字)的验证码。通过使用Math.random()函数配合字符数组,该程序能够有效地生成验证码并打印出来。
1万+

被折叠的 条评论
为什么被折叠?



