二、Java随机生成验证码
代码:
package com.Martin.RandomCode;
import java.util.Random;
public class RandomCode {
public static String RandomCode1(int n) { //随机生成验证码
int type;
String code="";
Random r = new Random();
for (int i = 0; i < n; i++) {
type = r.nextInt(3);
switch (type) {
case 0:code+=r.nextInt(10);break;
case 1:code+=(char)(r.nextInt(26)+65);break;
case 2:code+=(char)(r.nextInt(26)+97);break;
}
}
return code;
}
public static void main(String[] args) {
String result=RandomCode1(3);
System.out.println(result);
}
}