使用String生成五位随机验证码
import java.util.Random;
public class Code {
private static String s="abcdefghijklmnopqrstuvwxyz0123456789";
private static StringBuffer code;
public static StringBuffer getCode(){
Random random = new Random();
code=new StringBuffer();
for (int i = 0; i < 5; i++) {
code.append(s.charAt(random.nextInt(s.length())));
}
return code;
}
public static void main(String[] args) {
System.out.println("五位随机验证码是:");
System.out.println(Code.getCode());
}
}