Scanner sc = new Scanner(System.in);
System.out.println("请输入随机验证码个数");
int num = sc.nextInt();
String code = getCode(num);
System.out.println(code);
}
private static String getCode(int num) {
String code = "";
String date = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Random r = new Random();
for (int i = 0; i < 5; i++) {
int index = r.nextInt(date.length());
code += date.charAt(index);
}
return code;
}
Java随机验证码
最新推荐文章于 2024-08-30 18:40:43 发布