Java教程

3

本文主要是介绍3,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

简单验证码生成程序

通过数组存储26个大写字母和26个小写字母和0-9数字

随机成0-61的4个数字对应数组下标

输出四位验证码。

package 验证码程序;

import java.util.Random;

public class Number {

public String []array= {"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"};
public int a,b,c,d;
public String creat() {
Random rand =new Random();
a=rand.nextInt(61) + 0;
b=rand.nextInt(61) + 0;
c=rand.nextInt(61) + 0;
d=rand.nextInt(61) + 0;
String e = array[a]+" "+array[b]+" "+array[c]+" "+array[d];
//System.out.println("验证码:");
//System.out.println(array[a]+" "+array[b]+" "+array[c]+" "+array[d]);
return e;
}
}

这篇关于3的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!