public static void main(String[] args) { String code = creatcode(5); System.out.println("随机验证码是:" + code); } public static String creatcode(int n) { String code = ""; Random rs = new Random(); for(int i = 0; i<n; i++) { int type = rs.nextInt(3); //生成随机大小写字符以及数字 switch(type) { case 0: char ch = (char)(rs.nextInt(25)+65); code +=ch; break; case 1: char ch1 = (char)(rs.nextInt(25)+97); code += ch1; break; case 2: code += rs.nextInt(10); break; } } return code; }
Java输出随机验证码
最新推荐文章于 2023-02-01 21:13:28 发布