用java写一个随机获取验证码的主函数(也叫方法)
package day8;
import java.util.Random;
public class code {
public static void main(String[] args) {
System.out.println(getCheckCode());
}
//验证码主函数
public static String getCheckCode() {
String s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
Random r=new Random();
String str ="";
for (int i =1;i <=4;i++){
int index =r.nextInt(s.length());
char c= s.charAt(index);
str +=c;
}
return str;
}
}