importjava.util.Arrays;importjava.util.Random;publicclassVerificationCode{publicstaticvoidmain(String[]args){String[]CHARS={"3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y"};boolean[]charFlags=newboolean[CHARS.length];String[]verifyCodes=newString[6];Randomran=newRandom();for(inti=0;i
2 回答
吃鸡游戏
TA贡献1829条经验 获得超7个赞
具体是哪一行看不懂呢?这个就是声明了一个验证码可取值数组CHARScharFlags的每个值对应了每个char是否已经用到过。(这里的目的是生成的验证码不会出现重复字符比如AA1234,两个A重复了)verifyCodes是最终生成的验证码数组。代码逻辑翻译过来就是:每次从CHARS里面取一个字符,看这个字符是否已经用过,没有用过就放到最终的验证码数组verifyCodes中。然后取下一个,如果从CHARS中取出的字符已经用过,则再随机生成一个下标,重新取一个字符。直到取到6个不重复的字符为止。
添加回答
举报
0/150
提交
取消