验证码的思想和代码解析

public class GetCode {
public static void main(String[] args) {
String string=new String(“abcdefghijklmnopqrstuvwxyz”);
StringBuffer strings = new StringBuffer("");//StringBuffer 内容可变
for (int i =1; i<=4;i++){
int a = (int)(Math.random()*25);//使用random方法随机获得一个0-25的数字
char x = string.charAt(a); // 将string字符串转化为单个的字符 strings.append(x); //将x字符 追加到 StringBuffer原参数里面 如 “”+“a”
}
String code = strings.toString(); //将StringBuffer 转换成 String类型输出 System.out.println(code);
}
}

你可能感兴趣的:(笔记)