import java.util.Random;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
while (true) {
String n = getCaptcha();
System.out.println("验证码为:"+n);
System.out.println("请输入验证码:");
Scanner sc = new Scanner(System.in);
String s = sc.next();
if (s.equalsIgnoreCase(n)) {
System.out.println("验证成功!!");
break;
}else{
System.out.println("验证码刷新,请重新输入!");
}
}
}
public static String getCaptcha() {
StringBuilder sb = new StringBuilder();
for (char i = 'a'; i <= 'z'; i++) {
sb.append(i);
}
for (char i = 'A'; i <= 'Z'; i++) {
sb.append(i);
}
for (char i = '0'; i <= '9'; i++) {
sb.append(i);
}
StringBuilder s = new StringBuilder();
Random r = new Random();
for (int i = 0; i < 4; i++) {
int n = r.nextInt(62);
s.append(sb.charAt(n));
}
return s.toString();
}
}