首页 > 代码库 > Java开发中经典的小实例-(随机产生验证码)
Java开发中经典的小实例-(随机产生验证码)
import java.util.Scanner;
public class Test10 {
public static void main(String[] args) {
// TODO Auto-generated method stub
/*
* int[] num=new int[4];
*
* for(int i=0;i < num.length;i++){
*
* char ch=(char)(Math.random()*26+65);
*
* System.out.print(ch); }
*/
String number = "QWERTYUIOPASDFGHJKLZXCVBNM1234567890";
char[] num = new char[4];
for (int i = 0; i < 4; i++) {
num[i] = String.valueOf(number).charAt(
(int) (Math.random() * 35) + 1);
}
for (int j = 0; j < num.length; j++) {
System.out.print(num[j]);
}
}
}
Java开发中经典的小实例-(随机产生验证码)